How To Connect a Flame Detection Sensor With ESP32

To connect a Flame Detection Sensor to an ESP32 and glow an LED when a flame is detected, follow the steps below. I’ll provide both the wiring details and the code.

Components Needed:

  1. ESP32 Development Board
  2. Flame Detection Sensor
  3. LED
  4. Resistor (for LED, typically 220Ω or 330Ω)
  5. Breadboard and Jumper wires

Wiring Connection Details:

Flame Detection Sensor to ESP32:

  • VCC (Flame Sensor) → 3.3V (ESP32)
  • GND (Flame Sensor) → GND (ESP32)
  • D0 (Digital Output) (Flame Sensor) → GPIO 18 (ESP32)

LED to ESP32:

  • Anode (Long leg)GPIO 19 (ESP32)
  • Cathode (Short leg)220Ω Resistor → GND
// Define pin numbers
const int flameSensorPin = 18;  // Flame sensor digital output connected to GPIO 18
const int ledPin = 19;          // LED connected to GPIO 19

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  
  // Set the pin modes
  pinMode(flameSensorPin, INPUT);  // Flame sensor input
  pinMode(ledPin, OUTPUT);         // LED output
}

void loop() {
  // Read the value from the flame sensor
  int flameDetected = digitalRead(flameSensorPin);
  
  // Print the flame sensor value for debugging
  Serial.println(flameDetected);
  
  // If flame is detected, flameDetected will be LOW (because sensor output is active LOW)
  if (flameDetected == LOW) {
    // Turn on the LED
    digitalWrite(ledPin, HIGH);
    Serial.println("Flame detected! LED ON");
  } else {
    // Turn off the LED
    digitalWrite(ledPin, LOW);
    Serial.println("No flame detected. LED OFF");
  }
  
  delay(500);  // Delay to make the reading stable
}

Explanation:

  1. Pin Setup:
    • The flame sensor’s digital output is connected to GPIO 18 on the ESP32.
    • The LED is connected to GPIO 19 through a 220Ω resistor.
  2. Flame Detection Logic:
    • The flame sensor’s digital output is LOW when it detects a flame and HIGH when there is no flame.
    • Based on this, the code turns on the LED when a flame is detected and turns it off when there is no flame.
  3. Serial Output:
    • The sensor’s state (flame detected or not) is printed to the Serial Monitor for debugging.

How to Test:

  1. Upload the code to your ESP32 using the Arduino IDE.
  2. Open the Serial Monitor to view the status of the flame detection.
  3. When you bring a flame (like from a lighter or candle) near the sensor, the LED should turn on. If no flame is detected, the LED should stay off.