Flame detector
Detect a flame with an infrared flame sensor and sound an alarm.
Sensors · Beginner
In a real product: Gas boiler (Smart home): A flame sensor confirms the burner lit, and shuts the gas if it did not.
A flame sensor module has an infrared photodiode tuned to the light a flame gives off. It has two outputs: an analog one for how strong the infrared is, and a digital one that switches when it passes a threshold.
What you'll learn
- Using a sensor's analog and digital outputs together
- Active-low signals: this module's DOUT goes LOW on detection
- Building a simple alarm
How it works
AOUT goes to A0 and DOUT to pin 2. The more infrared the sensor sees, the lower AOUT goes. The module's comparator pulls DOUT LOW when the reading passes the threshold set by its trimmer, which means "flame".
The loop prints the analog level and, when DOUT is LOW, lights the built-in LED and sounds the buzzer.
Try this
- Raise the sensor's flame slider while it runs to simulate a fire.
- Trigger the alarm from the analog value instead, with your own threshold.
- Add a servo that "closes a valve" when a flame is found.
sketch.ino
// A flame sensor: AOUT on A0 (lower = more infrared), DOUT on pin 2 (LOW = flame). Buzzer on pin 8.
const int FLAME_ANALOG = A0;
const int FLAME_DIGITAL = 2;
const int BUZZER = 8;
void setup() {
pinMode(FLAME_DIGITAL, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int level = analogRead(FLAME_ANALOG);
bool fire = digitalRead(FLAME_DIGITAL) == LOW;
Serial.print("Flame sensor: ");
Serial.print(level);
Serial.println(fire ? " FIRE!" : "");
digitalWrite(LED_BUILTIN, fire);
if (fire) tone(BUZZER, 1500, 300);
delay(500);
}