Dimmable Astronomy LED Map Lamp


Pulse Width Modulation (PWM) to dim a map lamp

This is an update to the old LED map lamp using a wider range from dim to bright and updated LEDs with a more even and brighter light. There are two circuits, one for 4.5-5v (USB powered) and another for 9v-14v car battery connection. The LEDs are now flat top with a 1200MCD rating. I retrofitted one of the old lights to use the 5v board powering it off of a USB plug and swapping out the single LED for four brighter LEDs.


PWM divides a period of time, we'll use one second here, into equal time pieces. Just like a film your eye can't see the on and off flickering if the time frame is small, about 60-100 per second. For these lights we're dividing the second into about 4000 pieces. I say about because I'm using the internal oscillator and not a quartz clock for the CPUs clock speed. Testing some of the lamps gave me a value of about 3916 Hz, pretty close to the 4000 Hz value.

Each of these 3916 time frames is then divided into 256 pieces. The 10K Potentiometer's (Pot) resistance value is converted into a value between 0 (zero) and 255 in the ADC (Analog to Digital Converter). That number is the amount of of the 255 total that the LED will be on. If it's 10% on then about 25 of the 256 total will be on - the LED will be on 10% of the time. If the Pot is half way on the LED will be on 128 of the 256 on, which is on 50% of the time. The percentage of time on is called the duty cycle.

With the LED blinking on and off at 3916 times a second your eyes see it as a brightness level, not as flickering. The big difference between using PWM and using the direct resistance of a Pot to dim the LED is that PWM allows smoother control of the LEDs brightness. I never could find the perfect Potentiometer value to allow from full brightness to very dim using the full range of the pot.

Lamp On

This project uses a PIC microcontroller and you will need to be able to download the hex code into the PIC 12F683 before it will operate. The CCS C source code is near the bottom of this page.


3D Printer Light

A light weight 3D printer lamp, including a built-in circuit board box and a more traditional wood light. The 3D model is the lamp head upside down.


3D Light Head

Two PWM Map lamps

Above, A friend's one arm design using both a 4 LED and a 'hammerhead' 5 LED design.

There is also a 5 LED version that uses the same PWM controller.

Hammerhead Map Lamp

Each LED gets its own resistor that limits the maximum voltage to a safe level. With the resistors in the lamp head it allows the same design to be used for multiple voltages by using the appropriate resistors. I have a 5v and a 12v PWM circuit depending on the power supply. The battery weight on the base of the 5v lamps prevents the lamp from tipping then the head is extended from the base.

Pot and PWM Map lamps

A pair of map lamps. Top is the old Pot dimmer and below with the PWM dimmer. All of my map lamps are now upgraded to the PWM version.

Old and new LED arrangements

I recycled some of the old v1 dimmer lamps and turned them into the PWM dimmer lights. Left is the original LED head and right is the new head. The super bright flat end LEDS made for a much more even lighting. The side shield hasn't been installed on the new light yet. I ended up using opaque heat shrink tubing around each LED and it works well. A test using opaque paint on the side of the LEDs also worked.



5v Board soldered up

The finished 5v board before going into the light controller box. The three wires go to the 10k pot that controls the brightness. A dead USB mouse's cord was used to supply power to the left side connections. (Red wire is +5v, Black wire is ground). The right side connections are the pulse with modulated output. The circuit boards are available from OSH Park for the 5v controller, 9-12v controller and for the 4 LED head.

5v PWM circuit board

The same board showing the wiring. red wires are on the top of the board and blue are on the bottom. The brains of the board is 8 bit PIC 12F683 microcontroller. The PWM code was written in CCS C and uses about 10% of the chip's 2K of RAM. The 2N7000 MOSFET can only handle 200ma so I wouldn't run more than eight 20ma LEDs off of this board. The 5.1v Zener diode is for over voltage protection. The PIC hex code is here. You will need access to a PIC programmer to install it.



5v Power Bank

Pretty much any 5v DC power source will work with the map lamps. I like the cheap USB phone chargers with a built-in rechargeable battery. The dumber the charger the better. I say this because some of the smarter chargers have circuitry that shut off the power if the milliamp draw is below a certain level. These map lamps draw so little power that the smart batteries often turn off after a few seconds to a minute. The battery 'power bank' that I purchased are no longer available but a similar but untested version is on eBay. These usually have a USB A output socket and a USB B micro recharging input socket.


This is the 9-12v board. It needed a 7805 to give the PIC 5v. The circuit board is available from OSH Park for the 9-12v LED dimmer. it outputs both 5V and 12v PWM power fo the LED. It uses the same LED heads but the resistor may need to be changed if 12v is used. The ground is controlled by the MOSFET where it causes the power to blink on and off very quickly for the LED, in the example below each maximum pulse 'width' is 0.2553 ms, although the actual on time may only be a fraction of that total.

5v PWM circuit board


Max Pulse

At the lowest setting of the pot the LEDs are completely off and the circuit draws between 1 and 2 milliamp. The minimum pulse width the LEDs on is about 0.39% of the total. This doesn't go lower because the bottom if the POT values were clipped to guarantee that there is really an off even if the pot is slightly out of spec.

Mid Pulse

When I turned the pot knob to the middle position the value was almost exactly 50% (50.31%).

Min Pulse

At the highest setting the PWM value is between 99.9 and 100%, depending on the pot value. Good enough for a really bright light - or enough to get you kicked out of most star parties if left on.


Below is the 'Astro LED Light Dimmer.c' code (CCS Compiler)

/******************************************************************
//
//  Astronomy LED Light brightness controller code for a PIC 12F683
//  12/7/2015
//  
// SPAC Optical Lab   https://www.telescopelab.com
//
//                PIC 12F683
//               ------------
//        +5V  -| 1        8 |- GND
//             -| 2        7 |- 10k Pot input
//             -| 3        6 |- 
//       RESET -| 4/MCLR   5 |- PWM OUT
//               ------------
//
*******************************************************************/
              
#include <12F683.h>
#device ADC=10    // return a value from 0-1023 from the pot   
#include <STDLIB.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOMCLR,NOBROWNOUT,NOIESO,NOFCMEN
#use delay(clock=4000000)  // 4MHz is fast enough
             
#define PULSEMIN         0L   // LEDS OFF
#define PULSEMAX      0x3FF   // 1023 decimal - max resolution of the 10 bit ADC
#define ADCZERO           0   // first ADC input channel
#define ADCSTABILIZE    100   // us delay to stabilize
#define GAPMIN           10   // extra gap to leave at the bottom end to guarantee LEDs fully off
#define GAPMAX           23   // extra gap to leave at the top end to guarantee LEDs fully on
              
//  ASCII for www.TelescopeLab.com
#rom 0x2100 = {0x77, 0x77, 0x77, 0x2e, 0x54, 0x65, 0x6c, 0x65, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x4c, 0x61, 0x62, 0x2e, 0x63, 0x6f, 0x6d}
              
void main(void)
{
  int16 pulsewidth=PULSEMIN, lastpulsewidth=PULSEMIN;
                  
  setup_adc(ADC_CLOCK_DIV_32);             // slow down the ADC updates
  setup_adc_ports(sAN0 | VSS_VDD);         // analog port 7 active as input
  setup_adc(ADC_CLOCK_INTERNAL);           // use the PICs internal clock (good enough)
              
  setup_ccp1(CCP_PWM);                     //Enable Pulse Width Modulation Mode
  setup_timer_2(T2_DIV_BY_4, PULSEMAX, 1); // PWM range of 0-1023
  set_pwm1_duty(PULSEMIN);                 // Default to LEDs off
              
              
  while(1)
    {
    set_adc_channel(ADCZERO);      // select the pot input channel, set ADC=pin 7
    delay_us(ADCSTABILIZE);        // delay 100 microseconds for ADC to stabilize
    pulsewidth = read_adc();       // read pot on pin 7
                  
    if( pulsewidth < GAPMIN)
      { pulsewidth = PULSEMIN; }   // zero pulse (Off)
    if( pulsewidth > PULSEMAX-GAPMAX)
      { pulsewidth = PULSEMAX; }  // full pulse (Full On)
                      
    // only update PWM value if it changed
    if( pulsewidth != lastpulsewidth)
        {
        set_pwm1_duty((int16)pulsewidth);
        lastpulsewidth=pulsewidth;
        }
     }
} 
              

Mail