Updated
The KY-026 doesn't see fire. It sees infrared light, and a flame gives off plenty of it. Point it at a candle and its reading drops; blow the candle out and the reading climbs back.
That difference matters for everything you do with it, from where you test it to why it's no smoke alarm. Here's what's on the board, the real distances it worked at on the course's bench, and how to set it to trigger where you want.
The legs are long so you can bend them and aim the sensor. It sees best straight ahead, and the walkthrough's advice is simple: line it up with the flame.
With no flame in view, the course's sketch reads D0 = 0 and A0 close to 1023; in the walkthrough it sat around 1000. As infrared reaches the sensor, A0 falls. The stronger or closer the flame, the lower the number.
The comparator flips D0 to 1 when A0 drops below about 510, and the second LED lights. The trim pot doesn't move that 510 line. It shifts the analog reading: clockwise lowers it, counter-clockwise raises it. Turning the screw is how you decide how much flame it takes to cross the line.
Anything that gives off infrared counts, not just flames. Sunlight is full of it, and so are incandescent bulbs and heaters, so test away from windows and hot lamps.
When the course's sketch was written, it was tested with a candle in a brightly lit room. The results are worth knowing before you start:
In the walkthrough, a lighter about 30 cm (a foot) away still registered. So the KY-026 is more sensitive than most people expect. Calibrate it from across the desk, not up close.
| KY-026 pin | HERO Board | What it carries |
|---|---|---|
| A0 | A0 | How much infrared: lower means more |
| G | GND | Ground |
| + | 5V | Power |
| D0 | Pin 8 | Flame or no flame, at your set point |
Double-check the A0 wire. In the walkthrough it went into A5 instead of A0 by mistake. The reading sat at around 200 and wouldn't respond, and it took 20 minutes of troubleshooting to spot. An analog pin with nothing on it drifts, so a stuck, meaningless number usually means a wire is one hole off.
No library needed. This is the course's sketch, without its long comment header:
const uint8_t KY_026_DIGITAL_IN = 8; // D0: 1 when a flame is detected
const uint8_t KY_026_ANALOG_IN = A0; // A0: lower = more infrared
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(KY_026_DIGITAL_IN, INPUT);
pinMode(KY_026_ANALOG_IN, INPUT);
}
void loop() {
int ky026_Dval = digitalRead(KY_026_DIGITAL_IN);
int ky026_Aval = analogRead(KY_026_ANALOG_IN);
if (ky026_Dval == HIGH) // flame detected
digitalWrite(LED_BUILTIN, HIGH);
else // no flame
digitalWrite(LED_BUILTIN, LOW);
delay(150); // how often to check
// Uncomment to see what the sensor sends (you'll need it to calibrate)
// Serial.print("Digital Value: ");
// Serial.print(ky026_Dval);
// Serial.print(" | ");
// Serial.print("Analog value: ");
// Serial.println(ky026_Aval);
}It lights the board's built-in LED whenever D0 says flame. In the walkthrough the instructor suggests driving something useful instead, like a fan. Uncomment the Serial.print lines and open the Serial Monitor at 9600 baud, and you have everything you need to calibrate.
Every flame and every room is different, so calibrate again whenever you move the setup.
The course's notes are blunt: this is a sensor for learning and hobby projects, not for anything where a fire really matters. It can't tell a flame from sunlight, and it only sees what's in front of it. For safety, a smoke alarm does the job.
What it does well is notice a small flame that's meant to be there, or one that has just appeared. The course suggests checking a pilot light, or a switch that a flame turns on. A few more:
The KY-026 walkthrough is lesson 21 of the SensorKit course, and every module in the 37-in-1 sensor kit covers the rest of the case. The KY-028 uses the same red comparator board with a thermistor instead, and the analogRead article explains the 0 to 1023 reading.
37-in-1 Sensor Kit: The KY-026 and 36 more modules in a latching case, with the free SensorKit course: 31 filmed walkthroughs and example code.
HERO Board: The Uno-compatible board the SensorKit walkthroughs are built around, with its USB cable.
In the course's bench test a candle was easy to calibrate at about 1 m, and in the walkthrough a lighter still registered at about 30 cm. Closer than about 45 cm, a candle saturated it.
Neither directly. It detects infrared light, which flames give off, and it can't tell a flame from sunlight or a hot lamp. Don't use it as a fire alarm.
D0 gives a clean flame or no flame at the point you set with the trim pot. A0 gives the raw level, which falls as the flame gets stronger or closer. The course's sketch reads both.
It's saturated: the flame is too close, or there's sunlight or a hot lamp in view. Move the flame back to about a meter and set the trim pot again.