Introduction: Supercapacitor Programmable Attiny LED Flashlight

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!

Comments

author
kohellus made it! (author)2016-03-19

Made it! Fun little project, got me to know some attiny stuff and do more with them. Great instructable, thanks!

attinyflash.jpg
author
discostu956 (author)2016-01-05

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

author
rafununu (author)discostu9562016-01-06

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.

author
discostu956 (author)rafununu2016-01-06

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

author
johanmoberg (author)discostu9562016-01-06

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...

author
Omnivent (author)johanmoberg2016-01-13

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

author
rocketman221 (author)rafununu2016-01-07

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.

author
kondzio29 (author)discostu9562016-01-06

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

author
no joker (author)2016-01-10

i will vote for you

author
kondzio29 (author)no joker2016-01-11

Thank you!

author
Seeed Studio (author)2016-01-09

It's really funny.

author
kondzio29 (author)Seeed Studio2016-01-09

Glad that you like it :)

author
Sandbird (author)2016-01-07

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

author
kondzio29 (author)Sandbird2016-01-07

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

author
Sandbird (author)2016-01-07

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

author
Srijal97 (author)2016-01-05

Great design! Im gonna make one!

author
kondzio29 (author)Srijal972016-01-06

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

author
Srijal97 (author)kondzio292016-01-06

Haha, I did vote for you! Even though I have my own Ible in the Arduino contest: https://www.instructables.com/id/The-Companion-IC/ :)

author
kondzio29 (author)Srijal972016-01-06

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

author
dudes (author)2016-01-05

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.

author
kondzio29 (author)dudes2016-01-06

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 !

author
Electro_Dynamic (author)dudes2016-01-05

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

author

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.

author
rafununu (author)Electro_Dynamic2016-01-05

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.

author
ThomasK19 (author)2016-01-05

You could make a sliding dimmer with a long press of the button. The next long press could slide up to max again. Short press for cycling modes. Nice one!

author
kondzio29 (author)ThomasK192016-01-06

This is power of microcontrollers, I can change it anytime by reprogramming Attiny.
I think i will use that solution in my full size project with 3W cree LED. it will be more useful since it will produce more light. Thank you for commenting ande please vote on me if you like this project :)

author
rafununu (author)ThomasK192016-01-05

This is what I've done ! The system memorized the last direction of the dimming and went opposite for each long pressure. A double click stored the value in memory. Short press cycled from 0 to memory to max to memory again and so on.

About This Instructable

13,015views

237favorites

License:

Bio: Crazy and creative Industrial design student at Kielce Technology University.
More by kondzio29:Supercapacitor Programmable Attiny LED flashlightLemonator!  3D printed juice squeezer of awesomeness *updated*POD-1 the Ultimate 3in1 Photo accesory!
Add instructable to: