The IR flame sensor is a black photodiode that responds to the infrared from a flame, plus an LM393 comparator. It gives a digital “flame / no flame” output and, on 4-pin modules, an analog intensity.
On the ESP32 DevKit V1 power it from 3V3, read the alarm on D26 and the intensity on D32 (ADC1). The sketch lights the blue on-board LED whenever the digital output reports a flame.
Wiring
| ESP32 DevKit V1 | IR flame sensor module (LM393) | Wire | Notes |
|---|---|---|---|
| 3V3 | VCC | red | At 3.3 V the outputs can’t exceed the ESP32’s limit. |
| GND | GND | black | |
| D26 | DO | green | LOW when IR crosses the pot threshold (the DO LED lights). Digital use, so ADC2 doesn’t matter. |
| D32 | AO | yellow | ADC1. 3-pin modules have no AO — skip this wire. |
3.3–5 V part, 3.3 V board. Outputs follow the supply, so power the module from 3.3 V on ESP32 and Pico and from 5 V on Uno. Then DO and AO are always safe for your board.
Board quirks
- The sensor sees infrared at roughly 760–1100 nm. Sunlight, halogen bulbs and some TV remotes contain plenty of it, so a window behind the sensor triggers it. Point it away from daylight and shade it.
- Range for a lighter or candle is about 50 cm–1 m within its ±30° cone, set mostly by the pot. It cannot see smoke, and it cannot see a fire behind it — it is a project sensor, not a fire alarm.
- AO on D32 (ADC1) keeps working if you add Wi-Fi alerts later. AO falls as IR rises; the sketch flips it into a 0–100 % “IR level”.
- Avoid D2, D12 and D15 for DO: they are strapping pins, and a module holding them low or high at reset can stop the ESP32 booting or entering upload mode.
Code
// IR flame sensor module (4-pin, LM393) on an ESP32 DevKit V1.
// VCC → 3V3, GND → GND, DO → D26 (GPIO26, LOW = flame), AO → D32 (GPIO32, ADC1).
// A detector for experiments — not a fire alarm.
constexpr uint8_t DO_PIN = 26;
constexpr uint8_t AO_PIN = 32; // ADC1_CH4: keeps working with Wi-Fi on
constexpr uint8_t LED_PIN = 2; // on-board blue LED mirrors the alarm
void setup() {
Serial.begin(115200);
pinMode(DO_PIN, INPUT); // the module drives DO
pinMode(LED_PIN, OUTPUT);
Serial.println("Flame sensor: DO on GPIO26, AO on GPIO32");
}
void loop() {
bool flame = digitalRead(DO_PIN) == LOW;
int mv = analogReadMilliVolts(AO_PIN);
int ir = constrain(map(mv, 3200, 200, 0, 100), 0, 100); // AO falls as IR rises
digitalWrite(LED_PIN, flame);
Serial.printf("IR level %3d %% (AO %4d mV) %s\n", ir, mv, flame ? "FLAME DETECTED" : "no flame");
delay(250);
}// IR flame sensor module (4-pin, LM393) on an ESP32 DevKit V1.
// VCC → 3V3, GND → GND, DO → D26 (GPIO26, LOW = flame), AO → D32 (GPIO32, ADC1).
// A detector for experiments — not a fire alarm.
constexpr uint8_t DO_PIN = 26;
constexpr uint8_t AO_PIN = 32; // ADC1_CH4: keeps working with Wi-Fi on
constexpr uint8_t LED_PIN = 2; // on-board blue LED mirrors the alarm
void setup() {
Serial.begin(115200);
pinMode(DO_PIN, INPUT); // the module drives DO
pinMode(LED_PIN, OUTPUT);
Serial.println("Flame sensor: DO on GPIO26, AO on GPIO32");
}
void loop() {
bool flame = digitalRead(DO_PIN) == LOW;
int mv = analogReadMilliVolts(AO_PIN);
int ir = constrain(map(mv, 3200, 200, 0, 100), 0, 100); // AO falls as IR rises
digitalWrite(LED_PIN, flame);
Serial.printf("IR level %3d %% (AO %4d mV) %s\n", ir, mv, flame ? "FLAME DETECTED" : "no flame");
delay(250);
}Expected serial output
Flame sensor: DO on GPIO26, AO on GPIO32
IR level 1 % (AO 3170 mV) no flame
IR level 64 % (AO 1270 mV) FLAME DETECTED
IR level 2 % (AO 3140 mV) no flameFlame sensor: DO on GPIO26, AO on GPIO32 IR level 1 % (AO 3170 mV) no flame IR level 64 % (AO 1270 mV) FLAME DETECTED IR level 2 % (AO 3140 mV) no flame
Common errors
FLAME DETECTED all the time
The pot is turned too far (DO LED always on), or daylight is reaching the sensor. Turn the pot back until the DO LED goes off with no flame present.
AO always reads about 3200 mV
Normal with no flame. If it doesn’t change with a lighter at 20 cm, you have a 3-pin module (no AO) or AO is on the wrong pin.
Detects a flame only very close
Increase sensitivity with the pot, and aim the black IR LED straight at the flame; it is directional.