PEU
Flashlight Enthusiast
A post by a fellow CPFer inspired me to share with you all how to easily dim a LED with a microcontroller by using PWM (pulse wide modulation)
Here is the schematic:
and here is the source code:
This schematic shows how to dim a single 5mm led, but it can be used to control the enable pin of a buck/boost controller or a LDO or a FET...
To do it, just remove the led and send the uC pin to the enable pin of the device you are controlling. The PWM level is selected with the potentiometer.
And to make things even more simple, here is a zip file with the schematic, the source code and the HEX file for the ones that dont have a PICbasic compiler:
Variable_Brightness_via_ADC.zip
I hope this introductory post will help develop new cool flashlights
Pablo
Here is the schematic:

and here is the source code:
Code:
@ device INTRC_OSC_NOCLKOUT 'PIC12F683
DEFINE OSC 4
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
ANSEL = %00000011 ' GPIO.0 A/D in, rest digital
TRISIO = %00000011 ' GPIO.0 lectura AD,
pote var byte
oldvalue var byte
frecu con 800 'set PWM frequency
oldvalue=0
loop:
oldvalue=pote
ADCIN 0, pote ' (0-255) 'reads pot position
if oldvalue <> pote then
hpwm 1,pote,frecu
endif
GoTo loop
End
This schematic shows how to dim a single 5mm led, but it can be used to control the enable pin of a buck/boost controller or a LDO or a FET...
To do it, just remove the led and send the uC pin to the enable pin of the device you are controlling. The PWM level is selected with the potentiometer.
And to make things even more simple, here is a zip file with the schematic, the source code and the HEX file for the ones that dont have a PICbasic compiler:
Variable_Brightness_via_ADC.zip
I hope this introductory post will help develop new cool flashlights
Pablo