Introduction: Programmable LED

Picture of Programmable LED

Inspired by various LED Throwies, blinking LEDs and similar instructables I wanted to do my version of an LED controlled by a microcontroller.

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

An LED is used as output. As input I used an LDR, a light dependent resistor. This LDR changes its resistor as it receives more or less light. The resistor is then used as analog input to the microprocessors ADC (analog digital converter).

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

Picture of 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
- breadboard
- AVR programmer
- 5V power supply
- multimeter

- Eclipse
- CDT plugin
- WinAVR

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

Picture of Schematics

Some comments on the schematic.
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

Picture of Assemble on a Prototype Board

If you like to test your circuit, a breadboard is very handy. You may assemble all parts without having to solder anything.

Step 5: Program the Circuit

Picture of Program the Circuit
The controller can be programmed in different languages. Most used are Assembler, Basic and C. I used C as it matches my needs the best. I was used to C ten years ago and was able to revive some of the knowledge (well, only some ...).

To write your program, I recommend Eclipse with the CDT plugin. Get eclipse here and the plugin here

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

A very good tutorial on how to program AVR controllers with WinAVR is here 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 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

Picture of Soldering

If your circuit works on the breadboard you can solder it.

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.


HunsenA (author)2016-02-26

Is there a a video for this or is it just not popping up for me? Is there a YouTube tutorial I could watch?

kashifpawle (author)2015-12-04

I am currently pursuing mechanical engineers and very curious to know different types of electronic equipment which can control output as per the input.i came across arduino which I learned I want to kno that what are other programmable or non programmable microcontroller set having input and output, to be more precise a the compact one which I can incorporate in my projects at my level and who's difficulty level is some what around that of arduino

jonah marrs (author)2015-08-15

This instructable is immortal, thank you so much for sharing this.

Ploopy (author)2015-07-19


harrypotterrocks (author)2013-09-21

I can't find the avr programmer

techno guy (author)2012-05-19

can this be done on an arduino? if so, what's the code?

diy_bloke (author)techno guy2012-09-09

Yes it can, use the main C source code. Load that into yr arduino and compile. Often that will give you some error messages coz c specific code might be used but in thi scase it compiles without problems so I guess it would work.

rabril (author)2011-11-20

Is there anyway you could program an L.E.D. to stay on for one hour, turn off and turn back on after 11 hours?

ovan der beek (author)rabril2012-04-21

use an arduino

Orngrimm (author)2012-04-21

Haha! Cool idea! I like it.
Simple but nice.

Keep up the good 'ibles. :)

Also i think i may copy your method of "Ubersimple-3V-supply". Simply mindblowing ;)

caarntedd (author)2011-10-21

Love how this is put together, sort of looks like a primitive robot. Can robots be primitive? 5 stars.

thelastonekills (author)2011-08-22

that is soo cool. and a nice twist on a Throwie and aslo something good to improve skills.

robot1398 (author)2011-06-17

can i do this project with a pic by any chance and if yes schematic please

elecsl (author)2011-01-04

Greate project. Thanks for sharing. lk-tech

brooklynlord (author)2010-04-19

I don't really understand the C file and hex file....

Which am i supposed to program?
What is the other one for?

raykholo (author)brooklynlord2010-05-23

 if you want to use this for its intended purposes, upload the HEX file to the chip using an avr programmer.   (AVR Studio works to upload the hex).  If you want to change the code, then you would go to the "main.c" file...
Good luck!  and please reply back with any more questions.

raykholo (author)2010-05-23

 I am trying to read a pot using ADC on my attiny25v chip (same family as yours).  Is there anything I should know in regard to using your code as an example for my program in AVR Studio?  (this is for a Servo Tester - 10k pot to servo position, and also a button to center it).  

cefn (author)2010-03-27

Those commenting on the project might be interested by this alternative approach...

knektek (author)2010-03-25

instead of the low current led, perhaps a transistor would be handy, if you wanted to do it the other way round, use a mosfet.

godofal (author)2010-01-16

or, switch it on and power it from the battery, then u wouldnt need that jack!

zebratangozebra (author)2009-12-27

I love this !
Great ideas !
The freestyle assembly and minimal parts make it a less is more thing.
Thinking it might be interesting to maybe use a few more parts to make it look like a man or robot or something.

penester (author)2009-12-21

Hi Alex, im a c c++ c# programmer but am very interested in programing circuits as a hobby. 
Your tutorial is very simple im sure, but is there a chance you could point me to a ultra nubby circuit programing tutorial?

Any help would be good as ive never tackled this before.

alex_weber (author)penester2009-12-21

Ehm, are you the same guy as zezba9000? Or have you just copy'n'pasted the question?
I answered exactly this question (scroll down a bit to see it).

penester (author)alex_weber2009-12-23

Thank you so much my dear / alex_weber .

antitaengbasuraman (author)2009-12-07

how can you connect the IC to the computer? what is the connector, adapter or something to connect it and program to a computer?

with a programmer of course :D
for this type (attiny13 is an AVR chip) u can use the ghetto programmer described by the real elliot (just search it here) that works with the serial (printer) port of ur PC
or make/buy a USBtiny from that's a bit more expensive, but it works with ur USB port and doesnt need a power source.

hope it helped, if u have questions about the ghetto programmer, just PM me.

DjFluorescent (author)2009-11-24

 would the chip used here, to program the led, work with sound instead of an LED? i do alot of DIY synth projects and circuit bends. this would be a great addition if compatable.......    :)

alex_weber (author)DjFluorescent2009-11-24

In theory, yes. If you succeed, please let me know.

zezba9000 (author)2009-11-23

 Hi Alex, im a c c++ c# programmer but am very interested in programing circuits as a hobby. 
Your tutorial is very simple im sure, but is there a chance you could point me to a ultra nubby circuit programing tutorial?

Any help would be good as ive never tackled this before.

alex_weber (author)zezba90002009-11-23

take a look at
They have nice tutorials.
Or, another good starting point, especially for software developers, is the Arduino project. Really easy to get started.

trouble01 (author)2009-11-15


aliasjanedoe (author)2009-10-12

Can this only blink on and off, or can it fade also?  Such as if you program it using a light with a dimmer switch.  And does anywhere sell just the chip (not a full kit) with the program already on it?  When you remove the LDR, does the chip remember the last sequence entered from then on, even if the battery goes dead and has to be replaced?

alex_weber (author)aliasjanedoe2009-10-16

Yes, you could make it fading. For that you should google for PWM (pulse width modulation).

The recorded sequence is stored in RAM, so it would be lost if the battery goes dead. But you could store the sequence in EEPROM.

brunoip (author)2009-10-05

What is the difference between an ATtiny13V and an ATtiny13A ? Bruno

alex_weber (author)brunoip2009-10-16

The ATtiny13A is a replacement for the now "old" ATtiny13V and should be pin-compatible.

Jodex (author)2009-10-14

Looks like really cool!

ktalex (author)2009-10-04

is their such thing as a cell that powers when there is no light then when there is light?

bambangpe (author)2009-09-07

from electric become art so called electricart

shandoo (author)2009-09-03

Very nice one! Funky gadget!

tintenfisch (author)2007-11-29

Hi, can you recommend a store where I can get the Atmel ATtiny13v, the other components and the tools required? (breadboard and AVR programmer) Cheers, Jonathan

Rportal (author)tintenfisch2009-07-25 wide variety and stock. reasonable prices.

alex_weber (author)tintenfisch2007-11-29

Hi tintenfish,
looking at your nick, I assume you are living in a german speaking country?
For cheap ATtiny, have a look at:
They have breadboards and other components as well. For a programmer, check out the USBtinyISP from adafruits.

tintenfisch (author)alex_weber2007-12-01

Hi, thanks for your reply :) You are almost right.. it is a German word and I'm from Sweden, but I live in New York City right now.. Do you know any stores in the states? Also, should I get SOIC or PDIP? Is there any difference between them? Cheers, J

hoonflap (author)tintenfisch2007-12-17

sparkfun carries most of the atmel chips, and this instructable is a great intro to avr, with instructions on how to build a cheap programming cradle.

alex_weber (author)tintenfisch2007-12-02

Hi Jonathan, I'm sorry, I don't know any stores in the US. But you should look for the PDIP package, that's the one I used. The other one is an SMT package and very tiny. Cheers, Alex

Deyus (author)tintenfisch2007-11-29

You Can get a few different types of breadboards on this site how ever I don't know where to get the AVR programmer

Redgerr (author)2009-07-24

looks cool at the end and functional! very nice O-o im sure you could sell the programed ATtiny chips or sold everything in a pack to build yourself O_o just a thought ;)

alex_weber (author)Redgerr2009-07-24

If you look closely above, there is a link to the Tinker Store, where I sell kits of the Programmable LED ;)

jpr55 (author)2009-07-24

Hi Alex, Great project. I want to build a circuit for my son who is learning mores code. I think I will have no problem building the device but not sure how to program the ATtiny. How do you download the program to the ATtiny? Where do I get the Mymultipro device? I have a computer and I assume I build the program in sw named above and hit download to the Mymultipro and the rest is history. I also saw the video and it shows using light to train the circuit. Which method do you use. If you have to train the ATtiny with light as in the video then how do you protect it from outside influences? Thanks much, JPR55

alex_weber (author)jpr552009-07-24

Hi jpr55,

I am using now the USBtinyISP programmer from adafruit. Very handy.
You will need a breadboard to setup an programming environment, as you can not program the Programmable LED in circuit. You first have to program the controller and then solder everything together.
Here is another good starting point to learn how to program microcontrollers:

The circuit enters the recording mode by a light pulse, "dark - bright - dark", or the other way round, "bright - dark -bright". That way it should not take up outside influences. Although, I saw it on time happen as it got slowly darker, the ambient light triggered the switching.


About This Instructable




More by alex_weber:64pixelsArduino XMAS hitcounterSynchronizing Fireflies
Add instructable to: