Supercapacitor Programmable Attiny LED Flashlight





Introduction: Supercapacitor Programmable Attiny LED Flashlight

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:


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!



  • Make it Move Contest

    Make it Move Contest
  • Woodworking Contest

    Woodworking Contest
  • Casting Contest

    Casting Contest

We have a be nice policy.
Please be positive and constructive.





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.

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

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.

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

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.

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

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.

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

Glad that you like it :)

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

1 reply

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 :)

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

Post photos when you make one! I'd love to see it ! And if you like my project you can vote on me in the contests :)

Haha, I did vote for you! Even though I have my own Ible in the Arduino contest: :)

Thank you, your project is neat too! I voted !

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.