Light Weight, Long Life Flashlight
by RedDerek in Circuits > Microcontrollers
1236 Views, 6 Favorites, 0 Comments
Light Weight, Long Life Flashlight
My goal was to create a flashlight that is lightweight and lasts a long time between charges. This project has the LED of a streetlight, but is controlled to be dim to very bright. The result is a flashlight that I can use for 100 hours or more, depending on the battery size, in a dim mode, but can shine brightly to light up a room. The LED used is the same ones used in typical street lighting. The project uses a microcontroller to control the brightness of the LED.
This project involves a battery charger, an LED driver and a microcontroller. The circuitry is very simple to understand, and I will step you through the process. A complete schematic is presented as well as the files needed to get your own pcb built. The code for the microcontroller is also provided.
This is a great project to learn some electronics and play with a microcontroller.
Downloads
Supplies
· Atmel ICE programmer
o https://www.microchip.com/DevelopmentTools/Produc...
· Microchip Studio
o https://www.microchip.com/content/dam/mchp/docume...
· Battery – Lithium Polymer (LiPo), 3.7V 200mAh or better
o https://www.amazon.com/s?k=lipo+battery+3.7V&ref=...
· PCB
· Electronic components – about $6.00
The Circuit Explained
The complete schematic is shown here.
Downloads
The Charger Circuit
There are three parts to this schematic and I will explain each section. The first is the battery charger.
This uses a micro-usb B connector, P1, as the input. The battery charger ic, U1, is a smart charger that will charge the battery, BT1, to 4.2 Volts maximum. It will detect if a battery is present and if there are any problems with the battery. The charger will set the STAT pin, U1-1, to a low condition when charging. This will turn on the LED, D1. D1 will turn off when the charge is complete.
Here is the link to the MCP73832 datasheet:
https://www.microchip.com/wwwproducts/en/MCP73832
The Microcontroller
The next section is the microcontroller. I use a small ATtiny13A from Microchip as it is inexpensive and can operate in a low power mode.
The circuit board uses a programming header to allow easy connection to the Atmel-ICE programmer. There are pull-ups and pull-downs to ensure proper states are on the key pins of the microcontroller, U2. Pin 1, RST* needs to be held high, R8, so that the controller does not reset itself accidentally. R9 is used to ensure the signal on pin 6 is kept high and only goes low when the button, S1 is pressed. R3 is keeping pin 5 low, or the EN of the LED driver, to ensure that the LED is off.
Here is the link to the ATtiny13A datasheet:
https://www.microchip.com/wwwproducts/en/ATtiny13A
The LED Driver
The last section is the LED driver itself.
The LED driver, U3 PAM2804, is a PWM controlled driver. PWM means pulse-width-modulation. When the EN pin is set high, the driver turns on the output and lights up the LED to full brightness, but when this is pulsed low, the driver turns off. Thus, if the signal is high half the time and low the other half, the brightness is about half of the maximum. If it is high for a quart of the time, the brightness is about a quarter.
The inductor, L1, helps keep the current flow constant as this operates in a buck, or step-down, power supply configuration.
The LED used in this project is similar to ones used in streetlights. Thus, this is a VERY bright LED that can handle much current. The driver, when on, is driving the LED to the maximum brightness, but this is controlled by measuring the current through the LED. This current is sensed as a voltage on R4.
Here is the link to the PAM2804 datasheet:
Board Layout
The circuit board in these files have all the parts on one side, but is double-sided. The LED, D4, is very bright and can handles a lot of current, it also generates heat. So this board design has extras through hole vias to help dissipate the heat. Thus, the reason it needs to have two sides. There are also a few traces that run on the back of the board to make all the necessary connections.
There are several pcb board houses in the market. I use SunStone.com since they have good prices and deliver quickly. The file flashlight_gerbers.zip contains all the necessary files for the pcb house to build your board. The attached file flashlight_gerbers.zip.txt should be renamed to flashlight_gerbers.zip. This file can be sent to the board house, and they can send back a bare pcb.
The parts list for electronic components can all be obtained by my favorite distributor, DigiKey. I even included the distributor’s part number.
Board Assembly
Using a soldering iron, start with the smallest components first; these would be the resistors and capacitors. Then the ICs U1 and U3. Then the inductor L1 and D4. Add the U2 microcontroller and then JP1 and S1. A fine tipped soldering iron is recommended. When soldering the D4 LED and L1, be sure to allow the solder to fully melt and flow under the components. These D1 and L1 are the most challenging to solder. Ideally if you can get access to a heat gun that does not blow hard, but hot enough to melt solder, it makes the assembly of these two parts easier.
The last item to install is the battery itself. Solder the black, negative, lead into the hole on the right. Then solder the red, positive, lead into the hole on the left. There should be a “+” sign nearby.
(The photo above is another version I was working on, but has the same components. In this case the LEDs were mounted on the back side of the pcb, and there was no programming header - the reason for the clips.)
If interested in a kit that includes the board and components (less the Atmel-ICE), contact me. I am willing to put a list together and work out a reasonable cost once I have several orders.
Programming the Controller
Now the fun and creative part… programming. I have a simple program already written and extract and save the directory in the Flashlight_code.zip.txt file. Rename the file without the '.txt' extension so that it ends in '.zip'. Then it can be extracted.
Plug in the Atmel-ICE programmer and connect the small ribbon cable from the AVR connection on the Atmel-ICE, to the JP1 programming header. Be sure to ensure the red part of the ribbon cable is towards pin 1 of JP1.
Load up the Microchip Studio program and load the project that is in the directory you stored the Flashlight_code.
Once the project is opened, press Shft-Ctl-P to get the Device Programming window to open up. Select the “Atmel-ICE” tool and select the “ATtiny13A” as the Device. Press “Apply” button.
From the left side, select “Memories” and then press the “Program” button.
In order to make sure this flashlight is operating at its long life, you also have to set some fuses on the microcontroller. Select the “Fuses” on the left side. Set LOW.SUT_CKSEL to “Int. RC Osc. 128kHz; Start-up time: 14 CK + 0 ms”. Also, be sure the LOW.CKDIV8 is not checked. If it is checked and you Program the device, it will not be able to be programed again.
Now hit the “Program” button at the bottom right.
Your flashlight should now be operational.
Flashlight Operation
The flashlight should start up in the OFF state. Pressing the button once will turn it on to a low intensity. Pressing the button again will put it at maximum brightness. A third press of the button will turn it back off.
If the battery gets low, just use a basic USB to micro-USB cable to charge the flashlight. The circuit keeps the charging current down to about 150mA. Thus, if you have a 300mAh battery it will take about 2 hours to recharge. However, you could run the flashlight for about 75 hours at the low intensity setting before recharging.
This is showing the flashlight is charging. The blue LED, in this case is located on the back of the board.
Things to Explore
The software is very simple. There are some setups of the pins on the microcontroller and then the code starts. The code is documented, and you can play a bit with the duty_table. The duty_table is the list of the PWM values the microcontroller operates under. You can see there are three numbers: 0, 35 and 255. These represent how long out of a count of 256 that the microcontroller keeps the EN pin high. Thus, the 0 is for OFF and 255 is for ON. The 35 will turn the light on for 35/256, or 14% of the time, thus operating the light in a dimmed mode.
There are circuit changes that can be implemented, such as decreasing the battery charge time by changing the value of R2. Limitations on decreasing the charge time would be the current rate as a basic USB port cannot provide more than 500 mA. Another limitation is the maximum charge current for the battery. A small battery of 100mAh cannot take more than 200mA of charge current without damaging it.
You can also increase the maximum brightness of the LED by changing the value of R4; however, be careful not to over-drive the LED as you can damage it by driving too much current or overheating.
On this version of the project, I have moved the LEDs to the back side and strapped a battery to the pcb.