LED candle

This is a simple project, called  LED candle. I will be using yellow LED’s of 2 and a simple PWM code that runs on AVR (ATmega328p) chip make’s the LED flickering that almost looks like candle.  :P  for candle I will be using  LED’s+translucent paper.

two-yellow-leds       translucent-paper

 

led-candle

LED candle

 

circuit:

led-candle

 

code is very straight , Simple PWM code runs on ATmega48/328p

 

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>

#include <avr/interrupt.h>

void timer1_init(void);

void timer1_init()
{
DDRB |= 1<<PINB1; //
DDRB |= 1<<PINB2;

TCCR1A |= 1<<COM1A1 | 1<<WGM11; //
TCCR1A |= 1<<COM1B1;
TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS10; //
ICR1 = 49; //top value
}

int main(void)
{
timer1_init();

_delay_ms(1000);
while(1)
{
OCR1B = rand() % 47 + 1;

OCR1A = rand() % 47 + 1;

}
}

Comments

Submitted by nschreiber0813 on Sat, 2016-11-19 14:45

nschreiber0813's picture

Dear: viswesh

Thank you so much for this project. In case anyone didn't know this but I am actually a wiccan and use candles everyday for occult stuff. Nice!!! I might do something similar lol. Thanks!!!

From: noah

 

Submitted by Roxanna77 on Sat, 2016-11-19 19:24

Roxanna77's picture

This is great! I love LED candles, I once survived a house fire started by candles so I refuse to burn candles. Thanks for sharing this, going to make a couple. I'm thining same code could be used in a robot to give some "flame" look... 

~Roxy~
"Propeller Girl"
I tinker, therefore I am.....

Submitted by ggallant on Sun, 2016-11-20 20:43

ggallant's picture

I noticed a few little oddities in your code:

  1. You are using the "|=" operator without an initial value. If it is always after a reset this will work. To be safe, you might want change the first "|=" to a straight "=".
  2. Why the delay(1000) between the init and the loop and no delay(x) inside the loop. Are the rand() and "%"  functions slow enough to give a nice flicker?
Submitted by viswesh on Sun, 2016-11-20 21:10

viswesh's picture

initial or default port pin status of avr is toggle state,  yeah DDRB |= 1<<PINB1 works fine, _delay_ms(1000) used, no use at all can be ignored,  and yes rand() % will give flicker. 

thank you

Submitted by Protowrxs on Sun, 2016-11-20 19:02

Protowrxs's picture

Very cool - I didn't realize how straight forward that could be. 

Wonder if that code would work on an Atiny85 CPU?

Stephen

Submitted by Roxanna77 on Sun, 2016-11-20 20:41

Roxanna77's picture

I'm thinking might be too much current draw? But maybe not, average 5mm led is using 20 to 30 mah. I think the Attiny's are good for 40mah.

But would be easy to protect it with a couple transistors if one wanted to.

Submitted by viswesh on Sun, 2016-11-20 21:30

viswesh's picture

tranistor driver is not required  here, if we are using LED's like this, then we will need a transistor..

Submitted by viswesh on Sun, 2016-11-20 21:19

viswesh's picture

I have checked the code with the attiny84, it's working. it also works with 85 with slight changes in the register

Submitted by Mr_Booo on Sat, 2016-11-26 12:11

Cool

Video ! Or it did'int happen !

viswesh's picture
Author: 
viswesh
Last updated: 
19 Nov 2016 - 12:08
Robot type: