Flame Detection and Infrared Link
Flame Detection and Infrared Link
Overview
Section titled “Overview”Flame sensors and IR transmit/receive parts follow one idea in two directions: one “looks at fire”, the other “sends and receives signals”. Both are cheap and intuitive, but they are extremely sensitive to installation conditions — put them in the wrong place and they might as well not be there. By the end of this section you will be able to:
- Judge which fire sources a flame sensor can actually cover, and write the alarm semantics accordingly
- Use analogue plus a second hard threshold for two-level detection that reduces false alarms
- Build a working IR control link (receiver plus emitter plus protocol), and know how it differs from proximity sensing
- Record the failure modes of both device families in the acceptance document instead of explaining them after delivery
Prerequisites
Section titled “Prerequisites”Before starting this section, make sure you:
- Completed Sections 2 and 3 of Chapter 25
- Have a flame sensor module (AO plus DO, or AO/DO with dual LEDs) and an IR receiver head (HS0038 class)
- Have a lighter or candle for controlled testing (small amount, short duration, attended), plus a TV remote
Key Concepts
Section titled “Key Concepts”A flame sensor sees a specific radiation band
Section titled “A flame sensor sees a specific radiation band”Common parts use a near-infrared photodiode or phototransistor sensitive from about 760 nm to 1100 nm, responding to the flickering IR radiation of a flame. Consequences:
| Fire source | Detected reliably? | Notes |
|---|---|---|
| Open flame (paper, wood, oil, gas) | Yes | Strong radiation with 3–20 Hz flicker |
| Smouldering (no flame, smoke only) | Unreliable | Weak radiation, buried in ambient background |
| Electrical fire inside an enclosed cavity | Poor | Radiation is blocked by the enclosure — use smoke or heat detection |
| Sunlight, incandescent lamps, heaters | False alarms | Same-band radiation triggers it; needs shading plus feature analysis |
| Behind ordinary glass | Strongly attenuated | Glass absorbs this band; the line of sight must be direct |
Statement to use: a flame sensor is suitable for early warning of visible open flame; it does not replace smoke detectors, heat detectors or a fire alarm chain. Write this into the design and delivery documents, because it determines responsibility boundaries after an incident.
Use the flicker signature to separate fire from steady heat sources
Section titled “Use the flicker signature to separate fire from steady heat sources”Flames flicker at 3–20 Hz, whereas sunlight, lamps and hot bodies are essentially steady. So the decision rule should not be “above threshold equals alarm” but:
- Sample fast enough (e.g. a window covering well above 20 Hz)
- Compute variation inside the window (peak-to-peak or variance) — flames are far higher than steady light
- Alarm only when both conditions hold: amplitude over threshold and flicker signature matches
- Add time and count constraints (e.g. three consecutive windows)
This structure markedly suppresses false alarms from things like a phone flashlight. Sampling once per second cannot see flicker at all, leaving amplitude alone as the criterion — which drives both false and missed alarms up.
Two outputs and the comparator threshold
Section titled “Two outputs and the comparator threshold”Most modules provide AO and DO. The DO threshold is set by a trimmer as a hardware floor; AO is the software-adjustable primary criterion. Typical product design:
- AO as the primary criterion (enables flicker analysis)
- DO as a redundant hard threshold (local buzzer still fires if firmware runs away)
- Both states go into the payload, so a single-path trigger is always explainable
This is exactly the architecture of MQ-2 in Section 6, and can be merged into one selection rule: “analogue is the criterion, digital is the floor”.
An IR receiver head is not a photoresistor
Section titled “An IR receiver head is not a photoresistor”Integrated receivers such as HS0038 contain amplification, a band-pass filter (around 38 kHz) and demodulation. Therefore:
- They only respond to signals modulated near 38 kHz; steady IR illumination produces essentially no output
- Transmission must be modulated: a 38 kHz carrier switched to carry data (remote-control protocols such as NEC are carrier plus pulse-position encoding)
- Conversely, if you want a simple “LED always on/off” proximity or reflection detector, use a photoresistor or phototransistor — not a receiver head
This confusion is common: “IR remote control” and “IR proximity / reflection sensing” need different parts. Mixing them yields “it decodes the remote but cannot see the object”.
Practical limits of infrared
Section titled “Practical limits of infrared”- Line of sight: it does not pass through walls; reflections create false reception (black fabric absorbs IR, mirrors reflect strongly)
- Sunlight suppression: daylight is rich in near-infrared; outdoors or by a window, add a shading tube and a filter, and shorten distance
- Modulation frequency must match: receivers are narrowband; drifting from 38 kHz (36 or 40 kHz) costs real sensitivity
- Protocol must match: controlling home appliances requires the protocol they speak (NEC, RC5, …); your own links can use a custom format but should carry a checksum
- Range and angle: emitter current, lens angle and receiver field of view (typically ±15° to ±45°) jointly define usable geometry
Electrical and safety notes
Section titled “Electrical and safety notes”Flame modules and IR emitters usually run at 3.3–5 V; watch voltage drop over long wiring. Receiver outputs are active-low (pulled low when a signal is received), so mind pull-ups and the active level when configuring the GPIO. Never wire a flame-detection output straight into an execution loop such as exhaust fans or solenoid valves — such interlocks must come from safety-rated dual-channel logic with manual reset.
Implementation
Section titled “Implementation”Flame detection: amplitude plus flicker
Section titled “Flame detection: amplitude plus flicker”const uint8_t FLAME_AO = 34; // ADC1const uint8_t FLAME_DO = 36;
const uint16_t SAMPLE_INTERVAL_US = 1200; // ≈833 S/s, well above 20 Hzconst uint8_t WINDOW = 64; // about a 77 ms windowconst uint16_t AMP_THRESHOLD_ADC = 2600; // amplitude threshold, calibrate on siteconst uint16_t FLUCT_MIN_ADC = 180; // variation floor; steady light stays below
void sampleFlame() { uint16_t buf[WINDOW]; for (uint8_t i = 0; i < WINDOW; i++) { buf[i] = analogRead(FLAME_AO); delayMicroseconds(SAMPLE_INTERVAL_US); } uint16_t mn = 4095, mx = 0; for (uint8_t i = 0; i < WINDOW; i++) { if (buf[i] < mn) mn = buf[i]; if (buf[i] > mx) mx = buf[i]; } bool hot = mx >= AMP_THRESHOLD_ADC; bool flickering = (mx - mn) >= FLUCT_MIN_ADC; Serial.printf("flame: max=%u min=%u pp=%u amp=%d flick=%d\n", mx, mn, mx - mn, hot, flickering);}Field calibration: record the no-fire background distribution of max/min, set AMP_THRESHOLD_ADC above it, then confirm trigger distance and angle with a controlled open flame and log the observed variation range. Both thresholds must be measured values, attached to the delivery document.
IR receive: decoding NEC frames with an existing library
Section titled “IR receive: decoding NEC frames with an existing library”#include <IRremote.h>
const uint8_t IR_RECEIVER = 32; // needs a pull-up; avoid GPIO34–39 (no internal pulls)IRrecv irrecv(IR_RECEIVER);decode_results results;
void setup() { Serial.begin(115200); irrecv.enableIRIn(); // the library uses a timer for carrier and pulse-width measurement}
void loop() { if (irrecv.decode(&results)) { Serial.printf("ir: protocol=%d value=%08lx repeat=%d\n", results.decode_type, (unsigned long)results.value, results.repeat); irrecv.resume(); }}Key point: choose a GPIO that has internal pull capability for the receiver (the GPIO34–39 constraint from Section 2 applies here too). When holding a remote button, the same code repeats — de-duplicate in logic rather than treating repeats as new commands.
IR transmit: 38 kHz modulated frames
Section titled “IR transmit: 38 kHz modulated frames”#include <IRremote.h>
IRSender irsend(14); // the emitter pin needs a transistor/MOS driver for current
// Pack address and command into a 32-bit value and borrow the NEC frame// (NEC carries its own checksum; the checksum here is only for log cross-checking)void sendFrame(uint8_t addr, uint8_t cmd) { uint8_t checksum = addr ^ cmd; irsend.sendNEC((uint32_t)addr << 8 | cmd, 32); Serial.printf("tx addr=%02x cmd=%02x sum=%02x\n", addr, cmd, checksum);}Note: borrowing a mature protocol such as NEC is more robust than hand-rolling bit timing. Emitter current is significant, so a driver transistor is mandatory; driving the LED directly from a GPIO gives weak output and pushes the pin near its limit.
Library version note: the sender class name depends on the arduino-IRremote version — IRsend in 2.x and 3.0–3.2, IRSender from 3.3 onward. IRrecv and enableIRIn() are consistent across versions. If the build reports an undefined type, adjust that one line to the version you installed.
Verification
Section titled “Verification”Flame detection checks
Section titled “Flame detection checks”| Check | Expected result | Verified |
|---|---|---|
| 10 min background with no fire | Stable max/min distribution, basis for the thresholds |
|
| Incandescent bulb / phone flashlight aimed at it | Amplitude rises but variation stays low → amp=1 flick=0, no alarm |
|
| Controlled open flame at 30 cm | Both amplitude and variation exceed thresholds; alarm after 3 windows | |
| Remove the flame after an alarm | Alarm clears within 2–5 s (record the release time) | |
| With and without a shading tube | Daylight false alarms drop clearly | |
| DO versus AO cross-check | The DO trip point can be located with the trimmer and agrees with the AO criterion |
IR link checks
Section titled “IR link checks”| Check | Expected result | Verified |
|---|---|---|
| Aim a TV remote at the receiver | Protocol and code printed, repeat behaviour normal | |
| Self transmit/receive in one room | Error rate <1 % over 200 frames at the stated distance and angle | |
| Diffuse reflection path (no direct line of sight) | Reception via reflection proves the false-receive risk; assess geometry | |
| Direct sunlight on the receiver | Sensitivity drops visibly, validating shading design | |
| Shift modulation frequency (if adjustable) | Success rate falls away from 38 kHz, proving narrowband behaviour |
Troubleshooting
Section titled “Troubleshooting”Issue 1: the flame sensor alarms constantly
Section titled “Issue 1: the flame sensor alarms constantly”Symptoms: repeated alarms at a daylit location.
Possible causes: amplitude-only threshold; sunlight and warm lamps in the same band; a heater inside the field of view.
Solutions:
- Add the flicker criterion (the variation measure in this section) and recalibrate thresholds on site
- Aim away from direct sun paths; add a shading tube or narrow-field structure
- Increase the sampling window rate and confirm the firmware is actually sampling — once per second cannot see flicker
Issue 2: the receiver hears everything except my own transmitter
Section titled “Issue 2: the receiver hears everything except my own transmitter”Symptoms: remote-control codes decode fine, self-transmit/self-receive returns nothing.
Possible causes:
- Transmission unmodulated (LED steady or pure baseband switching) — a 38 kHz narrowband receiver cannot hear it
- Modulation frequency mismatched to the receiver
- Insufficient emitter drive current, so the signal vanishes beyond a few centimetres
Solutions:
- Transmit through the carrier (use the IRremote send API, not
digitalWrite) - Confirm the receiver’s centre frequency (38 kHz is most common) and align both ends
- Add a driver transistor to the emitter and limit long continuous duty
Issue 3: the flame reading never changes
Section titled “Issue 3: the flame reading never changes”Symptoms: AO is nearly constant and does not react when a flame is nearby.
Possible causes:
- The pin is not an ADC channel, or sits on ADC2 while Wi-Fi is active (Section 3 constraint)
- The module comparator is damaged, or AO is not actually brought out (some boards need a jumper)
- The field of view is blocked (misaligned enclosure aperture, protective film left on)
Solutions:
- Move to an ADC1 pin and run an A/B test with Wi-Fi disabled
- Check the board jumpers and silkscreen to confirm AO is wired out (some modules only expose DO by default)
- Inspect the aperture and filter visually; open the enclosure to probe directly if needed
Issue 4: short and unstable IR communication range
Section titled “Issue 4: short and unstable IR communication range”Symptoms: fine within 30 cm, heavy frame loss at 1 m.
Possible causes: weak emitter drive; receiver field of view versus mounting angle; ambient near-infrared background (sunlight, LED lamps).
Solutions:
- Increase emitter drive (transistor plus a properly chosen series resistor, respecting LED ratings)
- Shorten the optical path or add a narrow-field structure so wide-angle noise is excluded
- Add repeated frames and checksums to the protocol — put reliability in the link layer rather than in aiming
Best Practices
Section titled “Best Practices”- Do: state the flame alarm semantics as “early warning of visible open flame” in documentation, and explicitly note it does not replace smoke or heat detection
- Do: derive every threshold from on-site calibration, and archive thresholds with their calibration date
- Do: put checksums and sequence numbers in IR frames, and de-duplicate repeats in the application layer so commands do not run twice
- Do: drive emitter LEDs through a transistor, and pick a receiver GPIO with usable internal pulls
- Don’t: wire flame outputs into valve or fan actuation loops (that requires dual-channel safety design)
- Don’t: attempt flame-feature analysis with one sample per second
- Don’t: use a receiver head as an “IR intensity meter” — it is a narrowband demodulator, not a photoresistor
Summary
Section titled “Summary”Key points of this section:
- Flame sensors work in the 760–1100 nm near-infrared band: they see open flame, not smouldering, and glass or obstruction attenuates them sharply
- A reliable criterion needs amplitude plus flicker; at low sampling rates the flicker signature is invisible, so false alarms are inevitable
- AO as criterion, DO as floor — identical to the MQ-2 architecture and worth merging into one selection rule
- IR receiver heads are 38 kHz narrowband demodulators: transmit must be modulated; for proximity or reflection sensing use photoresistive parts instead
- Both families fail at the installation and calibration stage, so thresholds, field of view and shading design belong in the delivery document
Next section: ambient light and automatic switching — LDR versus BH1750, and how to write thresholds that do not mis-trigger.
We provide ESP32 ODM design-to-manufacturing services. From prototype to production — the team behind this tutorial can build it with you.
💡 Mention tutorial.imagrove.com in your Alibaba chat with us — get 10% off your custom project quote.
First published attutorial.imagrove.com/sensor-module-selection/08-flame-detection-and-infrared-link/Please credit Imagrove and link back to this page when quoting or republishing.
Questions or issues with this tutorial?
Sign in with GitHub to leave a comment. If a step fails for you, tell us — we verify it and update the tutorial.
© Imagrove · ESP32 IoT Tutorial