Supercapacitor Programmable Attiny LED Flashlight

14,526

244

28

About: Crazy and creative Industrial design student at Kielce Technology University.

Long time ago, I saw that some drivers in flashlights are using Attiny microcontrollers to deal with different modes. At that time I did not have arduino and I did not know how to program one.

Times have changed and my skills in programming grown. I wanted to program Attiny85 with arduino as ISP to achieve results similiar to ones that were in flashlights. I wanted at least three modes: 100% ->30% -> strobe
I had really hard time programming Attiny. I am really not good in programming so it took me some time to achieve results that you can see in the video.

In this instructable I will show you how to program Attiny using Arduino, modify code to set brightness levels, and simple wiring diagram.

This is more like example what can you make using my code. I am currently making full size CREE flashlight using the same setup, I am using power transistor to drive the LED from the 18650 cell and couple of 7135 current regulators. You can modify code to take advantage of two unused pins on Attiny.


If you like this instructable, please after reading it click like button, and if you think i have any chances in contests click Vote. Thank You!

Step 1: You Will Need

In order to make this flashlight you should have following tools:

  • soldering iron with solder and flux
  • Adruino
  • prototyping board
  • jumper wires
  • superglue

You will also need:

  • Attiny85
  • LEDs of your choice (I used pair of 5mm white LEDs)
  • 5.5V/1F supercapacitor
  • USB plug
  • two 220 ohm resistor
  • button

Step 2: Creating a Code.

My design takes advantage of Attiny85 sleep mode which draws only 0.7µ when used. My code looks like this:

HIGH MODE-> LOW MODE -> STROBE -> SLEEP

After each press of the button user loops between these modes.
I had a lot of trouble with sleep mode that requires use of the avr/sleep.h library. If you are using 1.6 version of arduino IDE it is included and ready to use with my code.

To program Attiny85 with your arduino you have to do following steps:

  • Upload Arduino ISP sketch from examples menu
  • put capacitor between RST and GND pin on your arduino
  • connect pin1 of attiny to pin 10 of your arduino board
  • connect pin4 to arduino GND
  • connect pin5 to arduino pin11
  • connect pin6 to arduino pin12
  • connect pin7 to arduino pin13
  • connect pin8 to +5V on your arduino

You have to install additional boards, you can do this by following these instructions: LINK

After you do this you have to choose your microcontroller from the list. In this case it is Attiny85 with 8MhZ internal oscillator, and programmer "Arduino as ISP" Than you can upload my code. In code you can easily change brightness of modes before uploading.

Step 3: Making It Compact.

Here you have diagram of connections. You can also take a look at assembly instructions to get better look at how to put things together.

I used file to make one side of the LEDs flat and then I glued them together using super glue. Next I soldered them in Parallel. I discovered that two LEDs gives decent ammount of light and don't need much power. You can solder as many LEDs as you want depending on what power source you will be using.

I used pin 5 as LED output, and pin 6 as button input so you can easily make sandwitch out of button and Attiny like you can see on the photo. Then comes pull down resitor between pin 6 and pin 4 (GND). Basically you are done... it is so simple circuit. I used 220 ohm resistor in series with LEDs and connected positive to pin 5 and negative to pin 4 (GND). Last thing you have to do is solder capacitor to pin 8 (positive) and pin 4 (GND/negative) and do the same for USB plug for charging.

I used Hot glue to keep everything in place and prevent shorts. It takes about 30 seconds to get the capacitor charged from USB port and it can shine about 10 minutes in HIGH mode and about triple of that in LOW mode. Strobe can be used as bicycle light at night since it is visible from distance.

Flashlight can be used when connected to USB port so in order to achieving full brightness you should consider using it with powerbank. You shouldn't worry about discharging your powerbank when in sleep mode since when capacitor is full it will draw no more than 0.9 µA.

Step 4: Thank You for Reading!

Thank you for being with me through all these steps. I hope you will enjoy your flashlight. Do not forget to post photos in the comments when you make it! Anyone is allowed to modify arduino code in order to add or change modes. I'd like to see what you can do with it! I'd love to see you using it to control 100W LED!

Share

Recommendations

  • Epilog X Contest

    Epilog X Contest
  • Pie Contest

    Pie Contest
  • Weaving Challenge

    Weaving Challenge

28 Discussions

1
None
dudes

3 years ago

First, I love this idea and will definitely be using it!

Second, I have a suggestion for increasing efficiency and run time. The resistor in series with the LED is limiting the current by dropping the voltage across it, but, in order to do that, it needs to 'burn off' the extra power, thus wasting energy. You're using a 220 ohm resistor and a white LED. Since the LED has a forward voltage of ~3.6v and the supply voltage is ~5v (when the cap is fully charged), that means the resistor is dropping 1.4v. 1.4v across 220 ohms gives a current of ~6.4mA, which in turn means the resistor is burning ~9mW of power while the LED is using ~23mW. That means the resistor is wasting ~28% of the total power (for the LED only, not including the ATtiny's power draw). Instead of using a resistor, simply limit the power via the PWM of the ATtiny. If 3.6v is needed for the LED for full brightness, it's simple to produce that with the PWM. 3.6 is 72% of 5, so a 72% duty cycle will imitate a 3.6v supply. 72% on the Arduino would be ~184 (180 works for simplicity). So if the LED is connected directly to the ATtiny but supplied with a 180 PWM rather than a 255 PWM, the resistor is not needed and thus that 28% is no longer wasted. The 8 PWM for the low level could be lowered to keep it the same brightness. And since you have two LEDs, it would be twice the benefit.

Sorry about the length, I get excited about stuff like this.

5 replies
0
None
Sanbordudes

Reply 4 months ago

I have done a similar setup where I ran a red LED with 5V (controlled by the Arduino UNO). You just have to keep the on time short enough (I just bit-banging and used NOP to keep the shortest on time possible). Life of the LED might get shorter, but I haven't seen issues yet.
Instead of using PWM, you can also keep the resistor, but put the ATtiny in sleep mode after the pin output is on. The Attiny uses about 5mA at 8MHz and 5V. Or still use PWM and put the ATtiny in IDLE instead of SLEEP and have the PWM Internal RC Oscillator at 128 kHz, and the power consumption of the ATtiny will drop to the 0.1mA. You can probably read the input voltage of the capacitor as well, and adjust the PWM accordingly. That will be a cool project to work out.
Since you use white LED's you get below the voltage forwarding of the LED's pretty quickly. In order to keep these bright below 3V you can look into creating a charge pump with the ATTiny by adding an inductor and transistor, which will definitely work when you strobe the output.

0
None
kondzio29dudes

Reply 3 years ago

Haha, it is okay! I like reading long comments! This is why I chose Attiny to drive a flashlight - because I can change settings on the run! However I will stay with my design since I found that when i did not used resistor it runs just a little bit shorter than with it and hey ;) it is supercapacitor! I can charge it in short period of time !

0
None
Electro_Dynamicdudes

Reply 3 years ago

The problem is if the LED receives 5 volt at any point in the PWM, the LED's life will decrease to like 3 seconds. LED's are bitchy about the voltage it recieves

0
None
peabody1929Electro_Dynamic

Reply 3 years ago

If one reads the Amel datasheet, especially the chart for IO pin output voltage vs sure current, it is obvious to the most casual observer that the PWM voltage can never reach 5V because of the IO Pin current limiter.

0
None
rafununuElectro_Dynamic

Reply 3 years ago

No, not really. A white Led can accept a forward voltage higher than 5V for a very short time, which is the case with PWM. I made such a device with a PIC where luminosity was constant by changing the PWM regarding voltage loss from the battery. The system worked from 4.2V to 3.5V.

0
None
aggx

1 year ago

Anybody have issues with the code? I can't seem to get mine to work at all. Circuit checks out, chip checks out. On Arduino version 1.8.5 at the moment.

0
None
discostu956

3 years ago

Very neat using capacitor as power source. Something I've been keen to try out and never gotten around to. Thanks for writing this up

6 replies
0
None
rafununudiscostu956

Reply 3 years ago

I'm in dubt regarding the USB port lifetime. Usually they provide 500mA max. Such a capacitor must draw several amps to charge, don't forget a capacitor physically acts as a short circuit in the beginning of the charge.

0
None
discostu956rafununu

Reply 3 years ago

it does depends what you are charging from. Tablet chargers etc are capable of up to a few amp, it's really only computers that are limited to 500ma these days. That high current you mention would only be for a very short period. Would it just take longer to charge the cap, our will it not charge that way? I'm not task experienced with capacitors in this way

0
None
johanmobergdiscostu956

Reply 3 years ago

It will charge fine and you wont hurt your usb port. Yes initially it would act as a short but the the current is limited from the computer, it just wont deliver more than 0.5 amps regardless how low resistance the device would have (just as your wall adapter only delivers 1-2 amps even if you would short it) . Here´s a charge curve for a capacitor.

http://www.schoolphysics.co.uk/age16-19/Electricit...

0
None
Omniventjohanmoberg

Reply 3 years ago

Too bad almost no manu's follow the specs. Most PC USB ports are not well limited, no matter what the USB specs demands.

0
None
rocketman221rafununu

Reply 3 years ago

Most of those little super caps have a very high ESR. As long as the ESR is over 10 ohms, it won't pull more than 500ma from a usb port.

0
None
kondzio29discostu956

Reply 3 years ago

Your welcome! Don't forget to vote on me in contests :)

0
None
Sandbird

3 years ago

That looks like an arduino nano in the picture, will an arduino pro micro do to upload the sketch ?

1 reply
0
None
kondzio29Sandbird

Reply 3 years ago

If your pro micro have USB port on board that you use to program the board, you can probably use it to program attiny. Just follow instructions :)