Table of Contents
In this we will see how to make a flame less electronic candle using Arduino. Believe me this is so much fun making this. The way a real candle looks it looks the same as it. You can use it for many decorative purposes.
As these are electronic candles this is flame less a best alternative to real candles. So Diwali the festival of light is coming soon and enjoy an eco friendly Diwali with a flame less candle.
COMPONENTS REQUIRED
S.N. | COMPONENT | QUANTITY |
1. | Arduino UNO | 1 |
2. | Arduino Cable | 1 |
3. | Breadboard | 1 |
4. | LED Yellow | 2 |
5. | LED Red | 1 |
6. | Resistor 220 Ω | 3 |
EXPLANATION
The project of electronic candle is based on PWM concept, if you don’t know about PWM take a brief – PWM stands for pulse width modulation, we know LED is a diode and works only in forward direction, but there is a twist, although it works is forward direction but if I give the led a less voltage it will be appears to be dim.
Same as this if I vary this voltage level then the intensity of the LED will also vary. In simple terms LED receives a DC cycle of different duty cycles (ON period). See figure
Take 3 LEDs, 1 Red and 2 Yellow to get the illusion of a real candle. Connect it to Arduino as shown in figure. Cover up Led with an opaque box or something like that but keep the top side a little open for light to come out.
CONNECTION DIAGRAM
CONNECTION TABLE
Arduino | LED’s Anode (+) |
9 | 1st Yellow Led |
10 | 1st Red Led |
11 | 2nd Yellow Led |
Arduino | LED’s Cathode (–) |
GND | 1st Yellow Led |
GND | 1st Red Led |
GND | 2nd Yellow Led |
ARDUINO CODE FLAME LESS ELECTRONIC CANDLE
/* Tutorial: https://pijaeducation.com/flameless-electronic-candle-using-arduino */ int led1 = 9; int led2 = 10; int led3 = 11; int fix = 60; int vary = 195; void setup() { pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); } void loop() { analogWrite(led1, random(vary) + fix); analogWrite(led2, random(vary) + fix); analogWrite(led3, random(vary) + fix); }
CODE EXPLANATION FLAME LESS ELECTRONIC CANDLE
In void setup (), Firstly define pin mode of Arduino pins that are 9, 10 and 11 as Output.
In void loop (), For PWM we are using function analogWrite (pinNumber, Intensity). Intensity can be varied from 0 to 255. One more function we are using is random (int_number), this means it will get random value from 0 to 195 and added by 60 to make 255, you can vary random number 195 (like “random(160)+90”) according to your convenience or requirement.
Here we are using another inbuilt function of arduino that is random() which is used for generating random numbers
SYNTAX
random(max)
random(min, max)
Returns: a random number between minimum and maximum-1 (long data type)