Flame sensor
An infrared eye on a comparator board. DO goes low when a flame comes within half a meter.
- 4 pins
- 1 setting
- In 2 projects
- In 1 lesson
The Flame sensor in brief
What it is, and every setting the properties panel gives it.
The flame sensor module, KY-026 style, is an infrared phototransistor standing off the end of an LM393 comparator board, with pins AO, GND, VCC and DO. It runs on 3.3 to 5 volts, so it wires straight to an Uno or an ESP32: VCC to the board’s supply, DO to any digital pin, AO to an analog input. It does not see fire as such, only near infrared between about 760 and 1100 nanometers behind a black lens. More infrared pulls AO lower, and DO goes low, lighting the lamp, when AO falls below the trimmer, the opposite of what most first sketches assume. Mokxi models the receiver’s current falling with the square of the distance, 100 microamps at 80 centimeters, saturating closer than about 30 centimeters, so at the default threshold of 0.5 a lighter trips it at about half a meter and the analog reading only really tells far from near. A slider moves the flame from 5 to 150 centimeters. Sunlight, bulbs, remotes, flicker, the 60 degree cone and response time are not modeled, and like the real board the comparator has no hysteresis.
- Family
- Sensors
- Pins
- 4
- threshold
- 0.5
4 pins
Named as the editor names them, so a wire lands where you expect it.
How to use a flame sensor with an Arduino
Wire VCC to 5 V, GND to GND and DO to pin 2. DO is an open-collector output with its own 10 k pull-up, and it goes LOW when a flame is close enough, so to the sketch a flame looks exactly like a pressed button: test for LOW, not HIGH. The example lights the LED on pin 13 while it does.
The trimmer sets the range. At the middle setting a lighter trips it at about half a meter; turn it up toward the supply and it reaches further. AO is worth wiring to an analog pin only to see the trend, since it bottoms out once the flame is within about 30 cm.
The module runs from 3.3 V as well, so on an ESP32 or a Pico power it from 3.3 V and DO stays at a safe level for the pin.
What is true about the Flame sensor, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
The light reaching the receiver falls with the square of the distance, and the
current follows the light: 100 µA at 80 cm, four times that at 40 cm, until the
transistor saturates at about 30 cm and AO sits on the floor. That makes the
datasheet's claim true: a lighter at 80 cm is just detectable with the trimmer turned
up to 0.8, and at the middle setting it trips at about half a meter. It is also why
AO is only good for "far" and "near", and why every sketch uses DO.
Not modeled
Everything else that is infrared. Sunlight through a window trips a real one, and so do an incandescent bulb, a TV remote and a warm radiator up close; here only the flame on the slider exists. The flame is steady, not flickering. The 60 degree cone and the board's response time are not modeled, and the comparator has no hysteresis, as on the real board.
From Flame sensor, in full.
See the Flame sensor in a project
2 built-in projects use it. Each opens in the editor, already wired.
Where it turns up in a lesson
One lesson places it in its own circuit.
The boards it is shown on
This board has a built-in project with the Flame sensor in it.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Flame sensor
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.