Realistic Candle

by MESHprj in Circuits > Electronics

1257 Views, 7 Favorites, 0 Comments

Realistic Candle

Realistic Candle

Hey everyone! Yeliz here again, with another project taking advantage of Sony's Mesh GPIO. This project builds on the concept of electric candles.

List of Parts:
Jumper Wires
Mini Breadboard
9V Battery
At least 1 LED cathode, preferably RGB
Mosaic Candle holder, at least 3"x3"x3"
Sound Sensor
Mesh GPIO Tag
9V Battery clip
Arduino UNO

Set Up Arduino

Start with copy-pasting this code into your Arduino.

const int flicker = 2;
const int blow = 3; const int ledPin1 = 9; const int ledPin2 = 10; const int ledPin3 = 11;
bool light = true; void setup() {
// put your setup code here, to run once:
pinMode(flicker, INPUT); Serial.begin(9600);
}
void loop() {
if(digitalRead(blow) == HIGH) {
light = false;
//Serial.println("light off");
}
else{
light = true;
}

if(light == true){
if(digitalRead(flicker) == LOW){
int light = random(100)+155;
analogWrite(ledPin1, light);
analogWrite(ledPin2, light/3);
analogWrite(ledPin3, random(120)+135);
delay(random(300));
//Serial.println("steady the lights");
}
else{
int light = random(90)+30;
analogWrite(ledPin1, light);
analogWrite(ledPin2, light/3);
analogWrite(ledPin3, random(90)+30);
delay(random(100));
//Serial.println("flicker a lot");
}
}
else{
analogWrite(ledPin1, 0);
analogWrite(ledPin2, 0);
analogWrite(ledPin3, 0);
}
}


Part of this code was learned by doing another instructables, "Realistic Flickering Flame Effect With Arduino and LEDs". The code from there gave me a great starting point for coding the flickering light effect.

Set Up the LEDs

IMG_7478.JPG
IMG_4735 copy.jpg
IMG_0205.JPG

I ordered a bag of these RGB LEDs for the sake of flexibility, since I didn't want a bunch of different bags of LEDs. These LEDs are also a lot brighter than the red and yellow ones I had lying around, so that's something to consider. That being said, we really only want red and yellow lighting to emulate a candle so you could just use those LEDs instead of RGB ones, totally up to you.

The pins on the RGB LED cathode are in the order of BLUE, GREEN, GROUND, and RED, with ground being the longest pin.

Two of the LEDs will use the RED and GREEN pins to make an orange-yellow, while the third LED will only use RED. The orange-yellow LEDs will share their power source, so they can go on the same row.

The GREEN pin uses a resistor of 1000ohms and then connect to pin 10, while the RED pins use a 220ohm resistor and connects to pin 9. If you end up using red and yellow LEDs, the resistor requirement might change. The RED pin on that LED goes to pin 11.

Keep a row on the mini-breadboard connected to ground on the Arduino, and connect that to the LED grounds.

With just these things plugged in and the Arduino successfully running the code, you should already have some flickering lights.

Finish Wiring Setup

IMG_7929.JPG
IMG_8296.JPG

Sound Sensor

The sound sensor will have at least 3 pins: Analog Out, Ground, and Power.

Wire Ground to the breadboard Ground row.
Wire Power to 5V on the Arduino.
Wire Analog Out to A-IN on the Mesh Tag. With "I/O" on top, it will be the 4th pin on the 2nd row.
Wire Ground on the Mesh Tag to the breadboard Ground row.

Mesh Tag

The Mesh tag will be the one to receive information from the sound sensor. It could have gone into the Arduino instead, but the Mesh tag is being used with the Motion Detector tag as well, so it's just cleaner to keep the Mesh tags as the "sensors" while the Arduino simply controls the flickering of the light.

Wire Mesh D-OUT1 to pin 2 on the Arduino.
Wire Mesh D-OUT2 to pin 3 on the Arduino.

D-OUT1 will determine whether or not the lights should flicker.
D-OUT2 will determine whether or not the lights should go out or turn on.

Battery

Clip the 9V battery to the clip and plug that in to the Arduino's power jack. At this point the Arduino does not need to be connected to the computer at all.

Setup Mesh App

Screenshot_20170821-145601.png
Screenshot_20170821-145619.png
Screenshot_20170821-145633.png
Screenshot_20170821-144721.png
Screenshot_20170821-145721.png
Screenshot_20170821-145640.png
Screenshot_20170821-145829.jpg
Screenshot_20170821-145641.jpg

From the images, the settings are in the same order as the Mesh Recipe, from left to right, top to bottom.

D-OUT1 determines whether or not to flicker the lights. The Recipe has the Motion Detector trigger the GPIO tag to set this value to HIGH to have the lights flicker, waits a few seconds, and then go back to LOW to bring the lights back to a stable condition.

D-OUT2 determines whether the lights should be on or off. If the output is HIGH, the light will turn off. As long as the output is on LOW, the lights will turn on.

The motion detector will also turn the lights on, so that you can feel really cool acting like a magician to turn the candle on, which will start with the flicker, and then stabilize. After that, the motion sensor just sets it to flicker every time it detects movement, like a normal candle would if you passed your hand over it quickly.

It's this easy! This project makes learning wiring, triggering, and basic code very easily.