loading
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.
<p>Hey, can you show me your reference on Attiny13 wit Arduino. I'm a newbie here...</p>
<p>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.</p><p>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.</p>
<p>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).</p>
<p>Cool!</p>
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?<br><br>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`<br><br>Yet when I plug in a 3v power source.. nothing, I'm not using a switch, just direct Vcc to pin 8. <br><br>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.<br><br>I assume whatever has gone wrong for me is to do with my chip or the flash. <br>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).<br><br>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.<br><br>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.<br><br>Other things to consider.<br><br>1) you might have a bad chip, can you try on another 85(better yet a 13)? the problem may be the chip.<br>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.<br>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<br>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.<br>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.<br>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.<br><br>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.<br><br>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. :-) <br><br>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)<br><br>I know the pin1 is correctly located, and my power supply is set and measured to 3v. I have tried 4 different chips.<br><br>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. <br />
You will have to learn bitmath for it to make sense.&nbsp; There is a great tutorial here http://www.arduino.cc/playground/Code/BitMath<br /> <br /> Check out AVRFreaks for other tutorials on avrs and avr programming.<br /> <br /> PORTB is the variable representing the pins on the attiny.<br /> <br /> PORTB &amp;= ~(1 &lt;&lt; thePin); <br /> and<br /> PORTB |= (1 &lt;&lt; thePin);<br /> <br /> is me flipping the bit(a single pin) on and off<br /> <br /> to add another led you can <br /> 1)&nbsp;simply connect the second led to the same pin<br /> 2)&nbsp;add a transistor to the pin, and connect both led to the transistor<br /> 3)&nbsp;add the new led to a new pin so it will work independently, you will need to update the code too<br />
How would you modify the code to work on the other pins?<br>i absolutely love this project BTW.
well I just checked the code. The two pins I'm using are 0x0 and 0x1. You just need to change the values there to address other pins... not sure what the values are off the top of my head... you will have to check the datasheet.<br><br>I chose these two pins because my ICSP programmer uses the other 6, though I believe you can use 6 of the pins for IO... two of them will always be needed for VDD and GND<br><br>This means you can get 6 leds working here with one pin to a led... you can get even more working with a multiplex, or charlieplex setup.. but again I have not looked at the datasheet in some time.
from what I can tell seems it would be easier to find another micro controller to add more leds since there are really only 2 general purpose i/o pins and need the other ones ffor programming.&nbsp; <br />
Did you have to burn the fuses on the chip? What settings did you use?<br><br>Thanks!
I did not touch the fuses, I think by default it is set to use the internal oscillator, and that was good enough for this project
Hi,<br/>I saw this project and decided to make it. Arther playing little in bascom I made pwm version of avr candle. Here is link to hex and bas file... <a rel="nofollow" href="http://www.transpapers.com/pwmcandle.zip">http://www.transpapers.com/pwmcandle.zip</a> circuit is not modified but during programming lfuse should be changed from default 6A to 7A (Divide clock by 8 internally; CKDIV8=0 disabled) so there is no flicker from pwm... I'm not code guru but I personally like more this pwm version... it's not hard for eyes and looks more like real fire. Basic code is also included in archive<br/>
just wanted to say thanks. I use a usbtinyisp on the mac so to program by tiny13 I used the following command avrdude -c usbtiny -p t13 flash:w:pwmcandle.hex -U lfuse:w:0x7a:m -U hfuse:w:0x1f:m Looking forward to seeing it this evening.
very cool, I can't wait to try it!!! thank you
Built this last nigh. In a dark room this gives you a pretty bad headache and drives you batty. We need to make some changes to the code to be nicer.
The flickering is being faked with a random on/off for two leds. It could definitely be better code, but if you obscure the device inside a pumpkin like I did, or even just under a napkin, I don't think the effect is that bad. Please put up some better code though. I would love to see some pwm on this bad boy, but I'm a newb, and I have not had much time to learn how to use the timers properly :( my hobby time seems to be less and less these days.
Yep that is why I said WE not YOU :). Yeah I had it obscured by frosted glass. I thought I was living the effects of a serious bender the headache I got. I tried adding in a delay, it got better but...... Love the Simple project.
what software and programmer did you use?
I used a USBTinyISP<br/><a rel="nofollow" href="http://www.adafruit.com/index.php?main_page=product_info&amp;products_id=46&amp;sessid=88e60ab616318e736357f41fcc38f51a">http://www.adafruit.com/index.php?main_page=product_info&amp;products_id=46&amp;sessid=88e60ab616318e736357f41fcc38f51a</a><br/><br/>the software I used to code was eclipse, with the avr-eclipse plugin. Then avrdude to program the chip. acr-eclipse has some nice hooks into avrdude which make it nice to use, just click and flash the chip.<br/>
I just built this as my first attiny13 project, and it worked perfectly! Thanks for the Instructable- it is terrific!
Nice project - I like the effect produced by the dual LEDs. Looking at them directly, it's not that great, but as a test, I placed a paper towel over the LEDs to act as a diffuser, and the effect was pretty cool with the lights off.<br/><br/>I felt that the blinking was a bit fast, so I added a delay based upon code by SolidSilver in his flickering LED candle project (thanks SS!).<br/><br/>BTW, I compiled and ran this on an ATtiny45, so we know it works on the 13 and 45 at least.<br/><br/>// =============================================================================<br/>// My version of the flameless candle code.<br/>// Function delay_ms and the _delay_loop_2 borrowed from an Instructable<br/>// by SolidSilver (who also helped me with his particular project) called<br/>// &quot;Flickering LED candle&quot;.<br/>//<br/>// Change the FLICK_DELAY as needed. I felt that a bit of delay gave the <br/>// resulting flicker a bit more realism.<br/>// - 10/20/2008 - cheeze69 on Instructables<br/>// =============================================================================<br/><br/>#include &lt;avr/io.h&gt;<br/>#include &lt;util/delay.h&gt;<br/>static inline void _delay_loop_2(uint16_t <span class="underline">count) </span>attribute<span class="underline">((always_inline));</span><br/>#define delay_us(us) _delay_loop_2((unsigned int)(((float)F_CPU*us)/4000000L))<br/>#define FLICK_DELAY 2000<br/><br/>void delay_ms(uint16_t x)<br/>{<br/> while(x--)<br/> {<br/> delay_us(1000);<br/> }<br/>}<br/><br/>int main(void) {<br/> int thePin = 0x0;<br/> long randVal;<br/> srandom(123); //random seed<br/> DDRB = 0x3; // B0-1 set to output<br/><br/> for(;;) {<br/> randVal = random(); // choose a pin<br/> if((randVal % 2) == 0) {<br/> thePin = 0x0;<br/> }<br/> else {<br/> thePin = 0x1;<br/> }<br/><br/> randVal = random(); //high or low<br/> if((randVal % 2) == 0) {<br/> PORTB &amp;= ~(1 &lt;&lt; thePin); // x &amp;= ~(1 &lt;&lt; n); forces the nth bit of x to be 0. all other bits left alone.<br/> }<br/> else {<br/> PORTB |= (1 &lt;&lt; thePin); // x |= (1 &lt;&lt; n); forces the nth bit of x to be 1. all other bits left alone.<br/> }<br/> delay_us(FLICK_DELAY);<br/> }<br/><br/>}<br/>
The delay definitely helps thanks for the suggestion. I was really surprised how good the effect was on mine with such crude code. SolidStates project is really cool as well, the package is way nicer, the code in that project is way nicer too PWM and real randomness!
tried your code, I'm thinking it might be too big for the 13, that or I'm doing something wrong. I borrowed the delay idea though and got something similar to fit on the 13, check out the zip on the last step and let me know how you think it compares.
Yeah, it is probably too big. The "rand" function uses a lot of memory and the tiny13 isn't packed with memory (that's why I bought a bunch of tiny45 instead of tiny13).
post hex file please
just uploaded new code and the hex in a zip on the last step, enjoy.
can this be accomplished by using a 555 timer?
I guess not. You only can set fixed duty cycle. Not random!
I'm not sure I could get the same "randomness" to create a flickering effect from a 555, but then I've never used a 555.
what are you using to get the code to the ic?
There is always the lovely Atmel STK-500, the dev board designed to program these things. They aren't as cheap as other options but they make things so easy it really is nice. Plus, most people don't know this, but students get 50% off on development kits from Atmel. You'd have to call them for details but it could save you $50 or so, i forget how much my STK-500 was. -Taylor
I build it out to a hex using eclipse and avr-eclipse, then I flash it with a USBTinyISP and a iscp to chip adapter I made myself.<br/><br/>The programer<br/><a rel="nofollow" href="http://www.adafruit.com/index.php?main_page=product_info&amp;cPath=16&amp;products_id=46">http://www.adafruit.com/index.php?main_page=product_info&amp;cPath=16&amp;products_id=46</a><br/><br/>The board is something liek this<br/><a rel="nofollow" href="http://www.evilmadscientist.com/article.php/avrtargetboards">http://www.evilmadscientist.com/article.php/avrtargetboards</a><br/><br/>
Could you add a short video of it, to let us see how realistic the effect is?
Yes I'll try to get a short video up of it tonight.
I've heard of people using music as the flicker... not only is it semi random (i guess music has a beat...) but you could tune it to get better results...

About This Instructable

36,180views

84favorites

License:

More by aballen:minimal larson scanner/cyclon Flameless candle from an attiny13 
Add instructable to: