To build a reliable flame detector sensor Arduino project, you need an Arduino Uno R3 (ATmega328P DIP variant), a 4-pin KY-026 flame sensor module featuring an LM393 comparator, and a 5V active buzzer. The sensor's infrared photodiode detects light in the 760nm to 1100nm wavelength range, peaking around 940nm, which perfectly matches the emission spectrum of a hydrocarbon fire. When the IR intensity crosses the threshold set by the onboard trimpot, the LM393 pulls the digital output low, triggering your alert.

Difficulty: Beginner/Intermediate | Time: 30 Minutes | Target Board: Arduino Uno R3 (Rev3)

Hardware Spec Sheet & Parts List

Before wiring, verify you have the exact module variants listed below. Generic 3-pin modules lack the analog output required for advanced threshold tuning, and passive buzzers require PWM code which complicates a simple alert build.

Component Exact Model / Variant Typical Price Technical Notes
Microcontroller Arduino Uno R3 (ATmega328P-PU DIP) $27.00 Ensure it's the DIP chip version for easy replacement if you short a pin.
Flame Sensor KY-026 (4-Pin with LM393) $2.50 Must have the blue 10k trimpot and 4 pins (VCC, GND, DO, AO).
Alert Buzzer KY-012 Active Buzzer (5V) $1.20 Active buzzers have an internal oscillator; just apply 5V DC.
Wiring 24 AWG Stranded Jumper Wires $5.00 Stranded wire resists breaking at the breadboard terminals.

Pin Mapping & Wiring Steps

The KY-026 module operates at 5V logic, matching the Arduino Uno R3 natively. The LM393 comparator on the module features an open-collector output, but the KY-026 board includes a 10kΩ pull-up resistor on the DO line, meaning you can wire it directly to a standard digital input without external resistors.

Sensor / Module Pin Arduino Uno R3 Pin Wire Color (Standard) Function
KY-026 VCC 5V Red Power supply (4.8V - 5.2V required)
KY-026 GND GND Black Common ground reference
KY-026 DO D2 Yellow Digital Out (LOW when flame detected)
KY-026 AO A0 Blue Analog Out (0-5V proportional to IR)
Buzzer + (VCC) D8 Orange Digital trigger for buzzer
Buzzer - (GND) GND Black Buzzer ground return
Pro-Tip: Keep the analog wire (AO) under 12 inches in length. The LM393 analog output has a relatively high impedance compared to a dedicated op-amp, making long wires susceptible to 60Hz mains hum, which will cause your analog readings to jitter wildly.
  1. De-energize the board: Ensure the Arduino is unplugged from USB before wiring.
  2. Connect Power Rails: Route 5V and GND from the Arduino to your breadboard power rails.
  3. Wire the Sensor: Connect the KY-026 VCC to 5V, GND to GND, DO to Pin 2, and AO to Pin A0.
  4. Wire the Buzzer: Connect the active buzzer positive leg to Pin 8 and the negative leg to GND. (If it doesn't sound later, swap these two).
  5. Verify Connections: Tug gently on each jumper wire to ensure it is fully seated in the breadboard clips.

Complete Arduino Code with Error Handling

This C++ code targets the Arduino Uno R3. It polls both the digital and analog pins, implements a state-change flag to prevent serial monitor flooding, and includes runtime error handling to detect disconnected sensor wires.

// Flame Detector Sensor Arduino Code
// Target: Arduino Uno R3 (ATmega328P)

#define DO_PIN 2
#define AO_PIN A0
#define BUZZER_PIN 8
#define SERIAL_BAUD 9600

// Analog threshold: Lower value = more IR light detected.
// Adjust based on your specific trimpot calibration.
#define FIRE_THRESHOLD_ANALOG 400 

bool fireDetected = false;
int consecutiveMaxReads = 0;

void setup() {
  pinMode(DO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  digitalWrite(BUZZER_PIN, LOW);
  
  Serial.begin(SERIAL_BAUD);
  
  // Wait for serial port to connect (useful for native USB boards, harmless on Uno)
  unsigned long startTime = millis();
  while (!Serial && (millis() - startTime < 2000)) {
    delay(10);
  }
  
  Serial.println("System Initialized: Flame Detector Active");
}

void loop() {
  int analogValue = analogRead(AO_PIN);
  int digitalValue = digitalRead(DO_PIN);

  // --- RUNTIME ERROR HANDLING ---
  // If the analog pin reads exactly 1023 consistently, the wire is likely 
  // disconnected or the sensor GND is floating (pull-up effect).
  if (analogValue >= 1022) {
    consecutiveMaxReads++;
    if (consecutiveMaxReads > 50) {
      Serial.println("ERR: AO_PIN_STUCK - Check GND and VCC wiring on sensor");
      delay(1000); // Throttle error messages
    }
  } else {
    consecutiveMaxReads = 0;
  }

  // --- FLAME DETECTION LOGIC ---
  // DO_PIN goes LOW when flame is detected.
  // AO_PIN drops below threshold when flame is detected.
  bool isFlame = (digitalValue == LOW) || (analogValue < FIRE_THRESHOLD_ANALOG);

  if (isFlame) {
    if (!fireDetected) {
      Serial.println("ALERT: Flame Detected!");
      fireDetected = true;
    }
    digitalWrite(BUZZER_PIN, HIGH);
  } else {
    if (fireDetected) {
      Serial.println("STATUS: Flame Cleared.");
      fireDetected = false;
    }
    digitalWrite(BUZZER_PIN, LOW);
  }

  // Print debug telemetry every 500ms
  static unsigned long lastPrint = 0;
  if (millis() - lastPrint > 500) {
    Serial.print("AO: "); Serial.print(analogValue);
    Serial.print(" | DO: "); Serial.println(digitalValue);
    lastPrint = millis();
  }
}

Debugging: First 3 Things to Check When It Fails

When your flame detector sensor Arduino build fails to trigger or throws errors, follow this ranked diagnostic path. These cover 95% of bench failures.

1. The Trimpot Calibration (Hardware)

The blue 10kΩ trimpot on the KY-026 sets the reference voltage for the LM393 comparator's inverting input. If it is factory-set to the extreme high or low end, the digital pin will either stay permanently HIGH or permanently LOW.

  • The Fix: Power the circuit. Point the sensor away from any heat/IR sources. Using a small Phillips #0 screwdriver, turn the trimpot clockwise until the module's green DO LED turns off, then back it off slightly counter-clockwise until it just flickers. This sets the baseline threshold.

2. Power Sag on the 5V Rail (Hardware)

The Arduino Uno's onboard 5V linear regulator can overheat if you are powering multiple modules, causing the 5V rail to drop to 4.2V. The LM393 requires a stable supply to maintain accurate comparator thresholds.

  • The Fix: Set your digital multimeter (DMM) to DC Volts. Probe the VCC and GND pins directly on the sensor module. You must read between 4.8V and 5.2V. If it reads lower, power the Arduino via the barrel jack with a 9V/2A supply instead of a weak USB port.

3. Compilation & Runtime Errors (Software)

If the Arduino IDE fails to compile, or the Serial Monitor outputs a specific error string, use this lookup table:

Exact Error String Ranked Causes & Fixes
error: 'AO_PIN' was not declared in this scope 1. You deleted or commented out the #define AO_PIN A0 line at the top of the sketch. Restore it.
2. You typed AO-PIN with a hyphen instead of an underscore. C++ does not allow hyphens in variable names.
ERR: AO_PIN_STUCK - Check GND and VCC wiring on sensor 1. The GND wire to the sensor is disconnected, causing the analog pin to float high via internal leakage.
2. The sensor's LM393 chip is damaged (shorted output). Replace the $2 module.
Safety Note: While this circuit is excellent for educational demonstrations and small-scale hobby projects, it is not a certified life-safety fire alarm. Never rely on a DIY Arduino flame sensor as your primary smoke or fire detection system in a residence. Always maintain UL-listed smoke detectors as required by the NFPA 72 National Fire Alarm and Signaling Code.

Extending and Simplifying the Build

Depending on your end goal, you can strip this project down to its bare essentials or scale it up into a home-automation node.

How to Simplify (Digital-Only Mode)

If you do not need to monitor the exact IR intensity via the Serial Monitor, you can delete the analog wiring entirely. Disconnect the AO wire from Pin A0. In the code, remove the analogRead() function and the FIRE_THRESHOLD_ANALOG logic. Rely solely on digitalRead(DO_PIN). This frees up an ADC channel and reduces code execution time, though you lose the ability to tune thresholds in software (you must use the physical trimpot).

How to Extend (IoT and High-Voltage Relays)

To make this a practical safety shutoff system:

  1. Add a Relay Module: Swap the Uno R3 for an ESP32 DevKit V1. Connect a 5V opto-isolated relay module to GPIO 5.
  2. Control a Gas Valve: Wire the relay's Normally Open (NO) contacts in series with a 12V DC solenoid gas valve. When the ESP32 detects a flame, it drops the relay pin LOW, cutting power to the solenoid and shutting off the gas.
  3. Add MQTT Alerts: Use the ESP32's WiFi to publish a payload to an MQTT broker (e.g., home/sensors/kitchen/fire: 1) to trigger Home Assistant automations, like turning on smart lights to full brightness and sending a push notification to your phone.

Frequently Asked Questions

Can a flame detector sensor Arduino setup detect a candle through glass?

No. Standard window glass (soda-lime glass) is highly opaque to infrared light beyond 1000nm. Because the KY-026 sensor relies on 760nm-1100nm IR wavelengths to detect fire, placing a pane of glass between the flame and the sensor will block the critical IR emissions, rendering the sensor blind. You must have a direct line of sight to the flame.

Why is my flame sensor Arduino giving false positives from sunlight?

Sunlight contains a massive amount of broadband infrared radiation, which easily saturates the 940nm peak sensitivity of the sensor's photodiode. If the sensor faces a window, the analog value will drop to near-zero, triggering your alarm. To fix this, mount the sensor in a shrouded 3D-printed tube (a "snoot") to limit its field of view to 20-30 degrees, pointing it strictly at the target area (like a stove burner) and away from windows.

What is the maximum detection distance for a KY-026 flame sensor?

Under ideal conditions (a large, bright hydrocarbon fire in a dark room), the maximum detection distance is roughly 80cm to 100cm (about 3 feet). For a standard cigarette lighter or match flame, the reliable detection range drops to 20cm to 40cm. The IR intensity follows the inverse-square law; doubling the distance reduces the detected light intensity to one-quarter. If you need greater range, you must use a specialized UV/IR flame scanner (like the Honeywell C7061) rather than a hobbyist module.

Do I need a pull-up resistor for the flame sensor digital out pin?

Not if you are using the standard KY-026 module. The LM393 comparator has an open-collector output, meaning it can only pull the signal line to ground (LOW), it cannot drive it HIGH. However, the KY-026 breakout board includes a 10kΩ surface-mount pull-up resistor wired to VCC. If you are building a custom PCB using a bare LM393 chip, you must add your own 10kΩ pull-up resistor between the DO pin and 5V, otherwise the digital pin will float and cause erratic readings.