Introduction: Electronic Candle With Light Sensor
I made an electronic candle which automatically turns on when it gets dark.
I used Arduino to detect the brightness of the room, to control the colour of RGB LED and to make LED blink like a real flame. For designing I used Inkscape and cut with laser cutter. For electronics part, I modified and used PCB board of my previous project.
What you need (quantity):
Arduino Pro Micro (1)
Multi SMD LED RGB (1)
SMD resistor 90Ω (2)
SMD resistor 150Ω (1)
Light dependent resistor (LDR) (1)
Resistor 2KΩ (1)
Pin header 1*4 (1)
Coin cell battery 2032 (2)
Acrylic board (white)
Step 1: Generate Cube Boxes
For designing candle, I used Inkscape. I made an box with tree patterns with MDF and put an smaller box with acrylic board inside of it. It diffuses the right nicely.
Design two cube boxes which size are 60mm and 50mm. This is a useful website I often use: BOXES.PY. You can generate design of different shapes easily and save as svg. Choose Boxes> ClosedBox. Set y, x, h as 60mm and 50mm and thickness depends on your materials. I used 3mm Acrylic board and MDF. Save as svg. If you have Inkscape in your computer, it automatically opens in Inkscape.
Step 2: Draw Trees
1. Go to Extensions> Render> Random Tree. I generated trees with Initial size: 100, Minimum size: 20. You can change the setting as you like.
2. Make the trees thicker. Change it to path so that you can modify the thickness (Path> Stroke to Path). Select the tree (path), apply Outset (Path> Outset). You can change the setting of the increasing rate (Command bar on the top> Preference on the right end of the bar> Behavior> Steps> Inset/ Outset by ).
Step 3: Create Tree Pattern on the Box
1. Draw a square which size is 55mm. Make its corner round by dragging down the mark on the right top corner of the square. Duplicate it five.
2. Place the tree(s) on the square. Select the tree(s) and the square and apply Difference (Path> Difference). Create five of this tree patterned square.
If Difference function doesn't work properly, try them bellow.
- Change objects and strokes to paths (Path> Object to path/ Stroke to path).
- Check Fill and Stroke (Object> Fill and Stroke). Make sure all paths are non-filled and stroke width is 0.02mm which laser cutter will cut.
- The order of objects matters. Difference function remove a shape of a newer object from an older object. Place the path which you want to cut out above the path which you want to use as a base. To change the order easily, you can duplicate the path which you want to cut out and use the new one.
3. Place the tree patterned squares on all the walls of 60mm cube box except the bottom. If you generate box design in BOXES.PY, two on the top are bottom and top walls, and other four are side walls of the box.
Step 4: Laser Cutting
1. Select all the parts of the two cube boxes, set as non-fill, stroke 0.02mm for laser cutting (Object> Fill and Stroke).
2. Laser cut 50mm box with white acrylic board and 60mm box with MDF board.
Step 5: Electronics and Wiring
I modified and re-used my previous project. Detailed PCB board design and manufacturing process are here.
1. Solder one of the legs of LDR and resistor (2KΩ). It would be better to use a wire between LDR and resistor because LDR should be out of the candle and it needs some distance. The wire goes to the GND pin on Arduino.
2. Solder a wire between LDR and resistor and it goes to the input pin (A0) on Arduino.
3. Connect another leg of LDR and anode wire from PCB board and it to the VCC pin on Arduino.
Step 6: Programming
I coded on Arduino for RGB LED to control the colour and to blink like a real flame, and for LDR to detect the brightness of the room.
I set threshold of the LDR as 100 but you can check with serial and change it as you like.
I wanted to have the colour of LED as orange, so I controlled the colour as R = 255, G = 65-125, B = 0.
To make LED blink like a flame, I used random delay. I only figured out this solution but it would have been better to use LED (not RGB) for blinking like a flame.
Here is the code:
int redPin = 3;
int greenPin = 5;
int bluePin = 6;
int photocellPin = A0;
int threshold = 100;
photocellRead = analogRead(photocellPin);
Serial.print("Analog reading = ");
if (photocellRead < threshold) // if the room is dark
setColor(255 ,random (65)+60, 0);
else if (photocellRead > threshold) // if the room is bright
setColor(0, 0, 0);
void setColor(int red, int green, int blue)
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
Step 7: Assembling
For power supply, you can use coin cell batteries. Connect GND pin(-) and Raw pin(+) on Arduino.
Put everything inside of the acrylic box (you don't need the bottom) except LDR which should be out of the box. Put the acrylic box in the MDF box.
Have a relaxing evening :)