Geeky Advent

Posted by on Dec 12, 2009 in avr, led | 31 Comments

LED Advent

It’s Advent season. And what do you do to let your geek shine? An LED Advent wreath of course.

The idea came to me after seeing Sprite’s minimalistic version of the Hackaday’s Flickering LED circuit. It’s a simple circuit that flickers LEDs and detects darkness. I thought that this could make a great little Advent wreath. My version should have 4 LEDs and should be support first, second, third and fourth Advent.

Parts and Schematic

advent schematic

The parts list is rather short:

  • ATtiny13V, 8-bit microcontroller, 1k flash RAM, 64 bytes SRAM
  • 4 * 3mm LEDs, yellow or orange, forward voltage ~ 2.0 V
  • CR2032 coin cell, 3 V, 230 mAh
  • Paperclip

There are no current limiting resistors in this circuit. Normally operating LEDs without them is not advisable because the LEDs will get damaged. But under certain conditions the resistors can be left out. For more on this topic, see Sprite’s computation or mine here.

How does it work

LED Advent wreath

The nice thing about this circuit is, that it needs no special components to detect darkness. It uses an LED for that. An LED is also a photodiode that can detect light of the same wavelength it emits. See here for more details. Sprite used an available ADC of the ATtiny13 instead of the “Reverse Bias” method.


The software is heavily based on Sprite’s version. Things I’ve changed:

  • Added support for four LEDs.
  • Removed calibration, replaced with hard wired values.
  • Added a bit sampling to the light measurements, because the values were a bit erratic.
  • Added a mode for first, second, third and fourth Advent, stored in EEPROM. Gets incremented at every reset.
  • Modified the watchdog code a bit to keep it generating interrupts instead of resets.

After power up, the watchdog gets enabled to generate an interrupt every two seconds. Then the current mode (0-3) is read from EEPROM, incremented and stored back. Then the endless loop is entered, where random values are used to flicker the LEDs. The ISR checks the ambient lighting and if it is higher than a certain level, sets a sleep flag. This flag is monitored in the main loop. If set it sends the controller in to power down mode to save battery power. The next interrupt will wake up the main loop.


2nd Advent

This circuit is soldered in “free form”, so no PCBs. It takes some time to get it done but it’s worth it.
All cathodes of the LEDs are connected to form the ring. The anodes are bent inwards to be soldered to pin 2, 3, 6 and 7 of the ATtiny13. A short piece of wire is connected to the common cathode and soldered to the GND pin.

Dead bug style

The microcontroller lies “dead bug” style on the coin cell. The GND pin is bent to the top, now connecting to GND of the battery. The VCC pin is bent to the bottom and soldered to the coin cell holder. The coin cell holder works as a clip, pressing the microcontroller onto the cell.

Some random notes:

  • Be patient.
  • Use as less solder as possible.
  • Don’t heat the pins of the controller for too long.
  • Be gentle while bending the controller pins. They come off easily. I added a tiny bit of solder.
  • BE patient ;)

The Result

LED Advent wreath

If you make one, please let me know. Send me a picture or post it on the tinkerlog flickr pool.

Happy third Advent …

Downloads and Links


  1. Snapel
    12. December 2009

    Oh, this one’s awesome. Unfortunately, I still don’t have any programmer for AVR’s. Any quickie programmer suggestions?

  2. Alex
    12. December 2009

    Look for USBtinyISP at adafruit. Small. Cheap. Just works.

  3. Jochen
    13. December 2009

    The USBtinyISPs are awesome. If you need something quick, there’s a hack out there to turn an Arduino into an AVR programmer (haven’t tried it myself though):

  4. Ben
    14. December 2009

    I like Pololu’s AVR ISP programmer. $2 cheaper, smaller (not that it really matters), has a couple other features built into it, and you don’t have to assemble it. I’ve used it a bunch with avrdude and linux, and AVR Studio 4.

  5. Luckeie
    14. December 2009

    Great idea! Did this work with the attiny12 too?

  6. Alex
    14. December 2009

    Hi Luckeie,
    the ATtiny12 has no ADC port so you would have to use the “reverse bias” method to detect darkness. And the ATtiny has no SRAM but that shouldn’t be a problem.

  7. David Storch
    14. December 2009

    Here’s a cool electronics project that you might enjoy. It’s a circuit bent keyboard mounted inside a rubber rain boot.



  8. PDiddy
    15. December 2009

    What an elegant design!

    I was reading the spritemod code for using LEDs as light detectors a couple of months ago and have been meaning to tinker with it for ages. Thanks for the inspiration :)

    How do you get your wires to be the right length? Is it mainly trial and error?

  9. Matt
    15. December 2009

    Very elegant, neat project – thanks for sharing it!

  10. Alex
    15. December 2009

    @PDiddy The wires are the leads of the LED so length is not the problem ;)
    But bringing them into form was very much trial and error.

  11. Advent - RELIBLOG
    15. December 2009

    [...] mehr dazu lesen möchte (oder das Teil nachbauen möchte), sei auf Alexander Webers Tinkerlog verwiesen. Der kommt passenderweise aus Hamburg, genauso wie der [...]

  12. brandon
    16. December 2009

    why does the led on pb1 not light up?

  13. Alex
    16. December 2009

    On third advent only three candles light up.

  14. Luckeie
    16. December 2009

    I have build the circuit with your tiny25 header board. Then i have downlaod the winavr-kit and compiled the c-program. All works ok, when i use the attiny13, when i take the attiny12 nothing works. Then i have modified the code: i have replaced the getLight-call in ISR(WDT_vect) with a constant value 200 and 400, new compiled but nothing works. ;-( I think i know to less for change the code to the ‘revers bias’-method. Have you example code?

  15. Alex
    17. December 2009

    Hi Luckeie,
    try google for “arduino led sensor”, that should give you a hint how to do it. I haven’t used it, so no sample code here.
    And if it’s working with the ATtiny13, why would you want to do it with an ATtiny12?

  16. Advent wreath from parts you have on hand - Hack a Day
    20. December 2009

    [...] an advent wreath made from six parts and a paper clip. Powered by a CR2032 3v button cell, the circuit has been free-formed using a [...]

  17. Sprite_tm
    20. December 2009

    Great article, nice build (deadbug-style ftw) and thanks for linking back to my site :)

  18. Sebastian
    22. December 2009

    I like this project very much! I built it with tiny45, but have some issues (it does not work :D ). The problem I think is the light sensing part or maybe some forever sleeping watchdog. When I change the AMBIENT_LIGHT to something high (like above 1000) it lights up from the beginning, but does not stop, even if i use very bright light. If I go below 1000 it does not light at all, even if I put it in a dark room. Someone have a guess on whats wrong?

  19. Sebastian
    22. December 2009

    Acctually it breaks just between 1023 and 1024 (surprise surprise!) But I can’t still figure out why it is not working :(

  20. Alex
    22. December 2009

    Hi Sebastian,
    that looks as if the ADC is not working, 1023 is the max value the ADC can read. The ADC is setup to use the internal reference (1.1V). So if PB4 gets somehow voltages above 1.1V it will report 1023. How do you power your setup?
    Another option for debugging is: use an Arduino to measure the voltage across the LED. You can even measure the voltage with a multimeter.
    And I’m not sure if the code works on a tiny45 without any adoption.

  21. Jacek
    22. December 2009

    I just built three of those as small christmas presents.

    Telling “Be patient.” while soldering cannot be done often enough. ;)
    I think I didn’t get it as beautiful as your one, but it’s nice. I really like this idea.

    Greetings from Aachen.

  22. Peter Lum
    24. December 2009

    Where can I get ATtiny13V cheaply?
    Also, can I use Blue LEDs?

  23. Alex
    24. December 2009

    Hi Peter,
    try digikey, price is not super cheap but ok.
    I haven’t tested blue LEDs, but I think they will not work properly, because they need about 3-3.2V and the coin cell is only 3V and there is a voltage drop along the microcontroller outputs.

  24. Sebastian
    24. December 2009

    I power the build with 3 and 5 volts (since I build in a lab and have loads of equipment, I can chose what is suitable for the moment). But I figured that the problem is the ADC; it is not working due to different instructions for the tiny13 and tiny45 to get the ADC running. Since I’m a very poor programmer, but more of an “electronist” I have to put some effort in making ” ADMUX = (1 << REFS0) | ADC2; " equivalent to the tiny45. This may take some time due to my programing handicap :)
    Merry Christmas to you all!

  25. Alex
    25. December 2009

    Try “ADMUX = (1 << REFS1) | ADC2;” …

  26. Student im Urlaub ? » Ein Weihnachtsgeschenk 2009
    29. December 2009

    [...] Alex von hat diese Idee wiederum aufgegriffen und ihr mit einer künstlerisch anmutenden Freiform-Verlötung der Bauteile einen wundervollen Hauch von Eleganz und Ästhetik verpasst. (Link zum Artikel). [...]

  27. tim
    25. January 2010

    Nice work Alex!
    I compiled the code with eclipse avr and
    used usbtinyisp with no problems whatsoever.
    I used your example for 1 of my 1st avr projects.

  28. bertbln
    19. November 2010

    gestern programmiert und gelötet, toller Effekt

  29. Season greetings from Halle (Saale) – Schönen 3.Advent
    21. November 2010

    [...] More at [...]

  30. Advent wreath
    26. November 2010

    [...] More at [...]

  31. Cool Advent, images
    1. June 2011

    [...] at Feel Free to [...]