This project simulates the behavior of a candle using modern technology. By combining an Arduino with a flame sensor, sound sensor, and WS2812b LEDs, we can create an interactive system where the LEDs light up when a real flame is detected and turn off when you blow air near the sound sensor. This fun and engaging project is perfect for hobbyists and beginners who want to explore the world of sensors and LED control.
Table of Contents
Required Components
To build this project, you will need:
- Arduino Board (e.g., Arduino Uno, Nano)
- WS2812b LEDs (2 LEDs recommended)
- Flame Sensor module
- Analog Sound Sensor module
- Jumper Wires
- Breadboard
- Power Supply (for Arduino and LEDs)
- Lighter (to simulate the flame)
Brief Explanation of Sensors
Flame Sensor
A flame sensor is designed to detect infrared light emitted by flames. It typically outputs an analog value proportional to the intensity of the flame or a digital HIGH/LOW signal based on a threshold. In this project, we use the flame sensor to detect the presence of a lighter flame near the sensor.
Sound Sensor
A sound sensor detects sound vibrations and converts them into an electrical signal. The sensor outputs a analog signal when the sound is detected proportional to the intensity of the sound and sent through output pin to microcontroller. In this project, the sound of blowing air is recognized by the sensor to turn off the LEDs.
Circuit Diagram
Below is the wiring layout for this project:
- WS2812b LEDs: Connect the DIN pin to Arduino pin D6. Power the strip using the 5V and GND pins of the Arduino.
- Flame Sensor: Connect the digital output pin (DO) to Arduino digital pin D2. Use 5V and GND for power.
- Sound Sensor: Connect the analog output pin (AO) to Arduino analog pin A0. Use 5V and GND for power.
Code
Below is the source code to be uploaded to Arduino through Arduino IDE.
How to Install Arduino IDE on Your PC
Also install Adafruit neopixel library through library manager and upload the code.
#include <Adafruit_NeoPixel.h> // Define pins #define LED_PIN 6 // WS2812b data pin #define FLAME_SENSOR 2 // Flame sensor pin #define SOUND_SENSOR A0 // Sound sensor pin // Define LED settings #define NUM_LEDS 8 // Number of LEDs in the WS2812b strip Adafruit_NeoPixel leds = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); // Variables bool isCandleLit = false; // State of the "candle" int flameThreshold = HIGH; // Flame sensor threshold (digital HIGH) int soundThreshold = 500; // Sound sensor threshold (analog value) void setup() { // Initialize components Serial.begin(9600); leds.begin(); leds.show(); // Turn off all LEDs at the start pinMode(FLAME_SENSOR, INPUT); } void loop() { // Read sensors int flameValue = digitalRead(FLAME_SENSOR); int soundValue = analogRead(SOUND_SENSOR); // Debugging output Serial.print("Flame Value: "); Serial.print(flameValue); Serial.print(" | Sound Value: "); Serial.println(soundValue); // Detect flame to light the "candle" if (flameValue == flameThreshold && !isCandleLit) { lightCandle(); isCandleLit = true; } // Detect blowing sound to extinguish the "candle" if (soundValue > soundThreshold && isCandleLit) { extinguishCandle(); isCandleLit = false; } delay(100); // Small delay for sensor stability } // Function to light the "candle" void lightCandle() { Serial.println("Candle lit!"); for (int i = 0; i < NUM_LEDS; i++) { leds.setPixelColor(i, leds.Color(255, 165, 0)); // Orange color leds.show(); delay(100); // Gradual lighting effect } } // Function to extinguish the "candle" void extinguishCandle() { Serial.println("Candle extinguished!"); for (int i = NUM_LEDS - 1; i >= 0; i--) { leds.setPixelColor(i, leds.Color(0, 0, 0)); // Turn off LEDs leds.show(); delay(100); // Gradual dimming effect } }
Working
- Lighting the Candle:
- When you bring a lighter near the flame sensor, it detects the flame and triggers the
lightCandle
function. - The WS2812b LEDs light up one by one, simulating the effect of a candle being lit.
- When you bring a lighter near the flame sensor, it detects the flame and triggers the
- Blowing Out the Candle:
- When you blow near the sound sensor, it detects the sound and triggers the
extinguishCandle
function. - The WS2812b LEDs gradually turn off, mimicking a candle being extinguished.
- When you blow near the sound sensor, it detects the sound and triggers the
Conclusion
This Arduino-based candle blowing project is a creative and interactive way to explore the use of sensors and LEDs. It’s a great starting point for learning about sensor integration and control systems. Experiment with different sensor thresholds and LED animations to make it your own. Happy tinkering!
Video: