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.