Flameless Candle From an Attiny13





Introduction: Flameless Candle From an Attiny13

I need to light my jack-o-lanterns, but this year I wanted something better then a regular candle. I want to flicker, but I want to get rid of the flame.

Any fire is dangerous, especially around kids, burny melty pumpkins stink, and regular candles need to be replaced quite often. So I searched around for a project to copy, oddly enough I could not find one I liked, so I created one myself. My original proof of concept was on an arduino, but that is a bit pricey for a simple candle. Once I proved it would work, I found a way to do it cheap.

Here is how I did it, out of the stuff I had on hand.

My first circuit and my first instructable.

Step 1: The Parts

I used what I had on hand. This came out to.

1) ATtiny13 x1
2) Red led x1
3) Yellow led x1
4) 100 ohm resistors x2
5) 8pin socket x1
6) thru hole switch x1
7) battery holder for 2AA batteries x1
8) perf board

resistors will vary based on your leds, you can probably find a better switch than I, you can even skip the perf board and wire it up dead bug if you want.

Step 2: The Circuit

My basic circuit, just wire it up like this.

Step 3: The Code

Here is the code I used. I just flash the leds, and try to add some randomness to it. The code could be better using pwm, and power saving features, but I don't know how to do any of that. My first non-arduino circuit, and my first instructable. The effect from the two leds is satisfactory in spite of how I did it. Varying brightness, color, and flickering.

Compile and upload the code to the tiny13, and you are good to go.

Feel free to post better code...

#include <avr/io.h>

int main(void) {
int thePin = 0x0;
long randVal;
srandom(123); //random seed
DDRB = 0x3; // B0-1 set to output

for(;;) {
randVal = random(); // choose a pin
if((randVal % 2) == 0) {
thePin = 0x0;
else {
thePin = 0x1;

randVal = random(); //high or low
if((randVal % 2) == 0) {
PORTB &= ~(1 << thePin); // x &= ~(1 << n); forces the nth bit of x to be 0. all other bits left alone.
else {
PORTB |= (1 << thePin); // x |= (1 << n); forces the nth bit of x to be 1. all other bits left alone.


Step 4: That Is It

You can sand the leds to diffuse the light, or use frosted leds, you can use a 2 color red/yellow led as well.

Put it in a ziplock bag to keep it from getting gross, and drop it in the pumpkin... instant flameless candle, and it will last for hours, and you don't have to worry about the kids messing with it.



    • Epilog Challenge 9

      Epilog Challenge 9
    • Science of Cooking

      Science of Cooking
    • Paper Contest 2018

      Paper Contest 2018

    We have a be nice policy.
    Please be positive and constructive.




    Hey, can you show me your reference on Attiny13 wit Arduino. I'm a newbie here...

    I'm not sure you can get ardunio on an attiny13. Also, the goal of this project was to make it small, and to learn a little about AVR GCC.

    If you want to do something similar on an arduino, get your led to go on/off... and then make use of the random function. That would be very similar to what I did here. There are lots of improvement you can make from there as well.

    so, how to upload the code? I'm willing to use any other method beside arduino to upload the code. Can you give me the link... i've stumbled upon countless web tutorial but i dont know where to begin with (for attiny13).

    Great project you have here. Currently building it. I do have a question. Suppose that I use a simple push button instead of the switch you used. Is there a line if code or a command that will shut of the power in say 20 seconds? I have an arduino book and I can't seem to find a good reference. Any help will be appreciated. Thank and keep up the good work.

    Sorry, my code runs in a continuous loop. The switch powers it on and off. The AVR does have a sleep mode, and you could rig it up with a watchdog to power it back up on the press of a button, but this code does not do that.

    Pardon my ignorance.. but would the article's supplied .hex file work (as is) on an ATtiny85?

    I'm using avrdude and the Adafruit USBtinyISP, and it seems to flash. No errors on the avrdude's output (everything done, ok, thank you). Command was `sudo avrdude -c usbtiny -p t85 flash:w:AVRCandle.hex`

    Yet when I plug in a 3v power source.. nothing, I'm not using a switch, just direct Vcc to pin 8.

    And If I pull the ATtiny85 and run VCC directly to the anodes (positive end) of the LEDs, they light up, which confirms the remaining circuit is valid.

    I assume whatever has gone wrong for me is to do with my chip or the flash.
    This is a nice simple instructable - it's Hello World. It's also like the third ATtiny tutorial I've tried following to no success (the others are more complex, for sure).

    Does anything stand out? Is my avrdude command correct? I am also assuming the ATtiny85 isn't radically different from the tiny13. Thoughts?

    I have not run avrdude from linux, but if you are seeing.... verifying... verified... done thank you. I believe you programmed the chip properly.

    I don't think there are any differences between the 85 and the 13, other than memory... but I could be wrong. You really have to look at my code and compare to the 85 datasheet, my code may be flipping the wrong pins for your 85. One thing to try is to compile the code posted by MixMasterM below... he was running it on an 85.

    Other things to consider.

    1) you might have a bad chip, can you try on another 85(better yet a 13)? the problem may be the chip.
    2) does your chip need 5v? check the exact version... if you have a 5v version, and are only providing 3v, that might explain why none of your attiny projects work.... and if you go up to 5v... increase your resistors.
    3) check the led datasheet, maybe it is working and the voltage from the pin is too low... if you tested the led to vcc through the 100 ohm resistors, this should not be a problem though
    3) have the fuses been altered? this project needs the internal oscillator set. I did not alter the fuses from factory settings for this project.
    4) check the batteries(use a multimeter), they may be low... 3v to an led usually burns it out, so if vcc is not, maybe your batteries are suspect.
    6) if you programmed the chip, it is probably oriented correctly in your circuit... but double check. Pin1 has a dot next to it. The datasheet will show you where each pin in my circuit diagram is physically on the chip.

    Don't get discouraged. Sometimes you just need to take a break, and come back with a fresh set of eyes. I know the project seems pretty basic, but coding c for the chip was quite challenging for me at the time.

    I can say though that this does work, several people have tested it successfully. Please let us know if you have some success.

    Thanks for the speedy and specific suggestions. I trust it works, and I am just having bad luck. :-)

    Of those suggestions, the two I should look into are the fuses and the pins (datasheet tiny 85 vs tiny13). I'll look into those two, and try the other code. When it is solved I'll post what the problem was (to help future time travelers who have the same problem)

    I know the pin1 is correctly located, and my power supply is set and measured to 3v. I have tried 4 different chips.

    FYI there are versions of the ATtiny 25/45/85, but they all handle the 2.7V to 5.5v range. The PU model (which I have) is 1.8v-5.5v.

    Can you explain the code? I'm trying to figure out how to add another led if possible.