The idea is to make the LED blinking sequence reprogrammable. This reprogramming can be done with light and shadow, e.g. you could use your flashlight.
This is my first instructable, any comments or corrections are welcome.
Update 12/08/2008: There is now a kit available at the Tinker Store.
Here is a video of reprogramming it. Sorry for the quality.
Step 1: How It Works
The controller has two modes of operation, one for recording a sequence, the other for playing back the recorded sequence.
Once the controller notices two changes of brightness within half of a second, (dark, bright, dark or the other way round), it switches to recording mode. In recodring mode the input of the LDR is measured multiple times a second and stored on the chip. If the memory is exhausted, the controller switches back to playback mode and starts to play the recorded sequence.
As the memory of this tiny controller is very limited, 64 bytes (yes, bytes!), the controller is able to record 400 bits. That is space enough for 10 seconds with 40 samples per second.
Step 2: Materials and Tools
- 2 x 1K resistor
- 1 x LDR (Light Dependent Resistor), e.g. M9960
- 1 x Low-current LED, 1.7V, 2ma
- 1 x Atmel ATtiny13v, 1KB flash RAM, 64 Bytes RAM, 64 Bytes EEPROM, 0-4MHz@1.8-5.5V
- 1 x CR2032, 3V, 220mAh
- soldering iron
- solder wire
- AVR programmer
- 5V power supply
- CDT plugin
Costs overall should be below 5$ without the tools.
I used the ATtiny13v because this version of this controller family is able to run at 1.8V. That makes it possible to run the circuit with a very small battery. To have it run for a very long time, I decided to use a low current LED which reaches full brightness already at 2ma.
Step 3: Schematics
The reset input is not connected. This is not best practice. Better would be to use a 10K resistor as pull up. But it works fine for me without and it saves a resistor.
To keep the circuit as simple as possible, I used the internal oscillator. That means we save a crystal and two small capacitors. The internal oscillator lets the controller run at 1.2MHz which is more than enough speed for our purpose.
If you decide to use another power supply than 5V or to use another LEDs you have to calculate the resistor R1. The formula is: R = (Power supply V - LED V) / 0.002A = 1650 Ohm (Power supply = 5V, LED V = 1.7V). Using two low current LEDs instead of one, the formula looks like this: R = (Power supply V - 2 * LED V) / 0.002A = 800 Ohm. Please note, that you have to adjust the calculation if you choose another type of LED.
The value of the resistor R2 depends on the used LDR. 1KOhm works for me. You may want to use a potentiometer to find the best value. The cicuit should be able to detect light changes in normal daylight. To save power, PB3 is only set to high, if a measurement is done.
Update: the schematic was misleading. Below is a correct version. Thanks, dave_chatting.
Step 4: Assemble on a Prototype Board
Step 5: Program the Circuit
To write your program, I recommend Eclipse with the CDT plugin. Get eclipse here http://www.eclipse.org/ and the plugin here http://www.eclipse.org/cdt/.
For compiling C language to AVR microcontrollers you will need a cross compiler. Lucky as we are, there exists a port of the famous GCC. It is called WinAVR and can be found here http://winavr.sourceforge.net/.
A very good tutorial on how to program AVR controllers with WinAVR is here http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial. Sorry, its in german but you may find thousands of tutorial pages on that topic in your language, if you search for them.
After having compiled your source, you have to transfer the hex file to the controller. That can be done by connecting your PC to the circuit using ISP (in system programmer) or using dedicated programmers. I used a dedicated programmer as it makes the circuit slightly easier by saving some wires and a plug. The drawback is, that you have to swap the controller between the circuit and the programmer every time you want to update your software. My programmer comes from http://www.myavr.de/ and uses USB to connect to my notebook. There are many others around and you can even build it yourself.
For the transfer itself I used a program named avrdude which is part of the WinAVR distribution. An example command line may look like this:
avrdude -F -p t13 -c avr910 -P com4 -U flash:w:flickled.hex:i
Attached you may get the source and the compiled hex file.
Step 6: Soldering
This can be done on a PCB (printed cicuit board), on a prototype board or even without a board. I decided to do it without as the circuit consist only of a few components.
If you are not familiar with soldering, I recommend that you search for a soldering tutorial first.
My soldering skills are a bit rusty but I think you get the idea.
I hope you enjoyed it.