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
- prototyping board
- jumper wires
You will also need:
- LEDs of your choice (I used pair of 5mm white LEDs)
- 5.5V/1F supercapacitor
- USB plug
- two 220 ohm resistor
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!