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
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
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.
Software
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.
Assembly
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.
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
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
- Source advent.zip
- Minimalistic flickering LEDs at Spritesmods
- Flickering LED circuit at Hackaday
- LED Menorah, also free form at Evil Mad Science
Oh, this one’s awesome. Unfortunately, I still don’t have any programmer for AVR’s. Any quickie programmer suggestions?
LikeLike
Look for USBtinyISP at adafruit. Small. Cheap. Just works.
http://www.adafruit.com/index.php?main_page=product_info&cPath=16&products_id=46
LikeLike
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):
http://www.uchobby.com/index.php/2007/11/04/arduino-avr-in-system-programmer-isp/
LikeLike
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. http://www.pololu.com/catalog/product/1300
LikeLike
Great idea! Did this work with the attiny12 too?
LikeLike
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.
Cheers,
Alex
LikeLike
Here’s a cool electronics project that you might enjoy. It’s a circuit bent keyboard mounted inside a rubber rain boot.
Video:
Photos:
LikeLike
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?
LikeLike
Very elegant, neat project – thanks for sharing it!
LikeLike
@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.
LikeLike
why does the led on pb1 not light up?
LikeLike
On third advent only three candles light up.
LikeLike
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?
LikeLike
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?
Cheers,
Alex
LikeLike
Great article, nice build (deadbug-style ftw) and thanks for linking back to my site :)
LikeLike
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?
LikeLike
Acctually it breaks just between 1023 and 1024 (surprise surprise!) But I can’t still figure out why it is not working :(
LikeLike
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.
HTH.
Cheers,
Alex
LikeLike
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.
LikeLike
Nice!
Where can I get ATtiny13V cheaply?
Also, can I use Blue LEDs?
LikeLike
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.
Cheers,
Alex
LikeLike
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!
LikeLike
Try “ADMUX = (1 << REFS1) | ADC2;" …
LikeLike
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.
thanks
tim
LikeLike
gestern programmiert und gelötet, toller Effekt
LikeLike