Arduino Uno IR Flame Sensor

This project demonstrates how to use an IR flame sensor module with an Arduino Uno to detect the presence of flames. The IR flame sensor detects infrared light emitted by flames and provides an analog voltage output. The Arduino reads this output and determines if a flame is detected based on a threshold value, which is displayed on the serial monitor.

How It Works

A flame sensor module is a specialised infrared detector tuned to the 760–1100 nm band, where a hydrocarbon flame emits strongly. The sensing element is a photodiode in a dark epoxy package — usually angled at 60° — that responds to that near-infrared signature rather than to visible light.

Most carriers, such as the KY-026, provide two outputs. The analog pin gives a continuous voltage that falls as flame intensity rises, useful for judging how close or how large a fire is. The digital pin is the output of an LM393 comparator that trips when the analog level crosses a threshold set by the onboard potentiometer.

The sensor cannot distinguish a flame from any other strong near-IR source. Sunlight, incandescent bulbs and heat lamps all trigger it. That is why a practical fire detector cross-checks the flame sensor against a temperature sensor or a gas sensor rather than acting on it alone.

Components Needed

  • Arduino Uno
  • IR Flame Sensor Module
  • Jumper Wires
  • Arduino Uno

Wiring to the Arduino Uno

Connect AO to A0 and DO to D2, with VCC on the 5 V rail and GND to ground. Either output alone is enough — use the analog pin when you want proportional readings and the digital pin when you only need a trip signal.

Any of A0–A5 (six channels) can take the analog output.

Set the threshold with the onboard potentiometer: hold a lighter at the distance you want to trigger at, then turn the pot until the module's indicator LED just lights. Verify it stays off with the flame removed.

Module pinArduino Uno pinFunction
A0 / AOA0Analog intensity — falls as flame grows
D0 / DOD2Comparator output, LOW when threshold crossed
VCC5VSupply
GNDGNDCommon ground

Build and Upload

Open the Arduino IDE and create a new sketch.

Copy and paste the provided Arduino code into the sketch.

Upload the code to the Arduino Uno.

Open the serial monitor with a baud rate of 9600.

Ensure the flame sensor is exposed to flames or heat sources. Observe the serial monitor to see the sensor values and flame detection status.

Example Code

Reading both outputs and requiring a sustained signal before alarming. Upload it with the board set to Arduino Uno and open the Serial Monitor at 9600 baud.

Reading both outputs and requiring a sustained signal before alarming
const int FLAME_ANALOG  = A0;
const int FLAME_DIGITAL = 2;
const int ALARM_SAMPLES = 5;        // consecutive hits before alarming

int hits = 0;

void setup() {
  Serial.begin(9600);
  pinMode(FLAME_DIGITAL, INPUT);
}

void loop() {
  int  level   = analogRead(FLAME_ANALOG);
  bool tripped = (digitalRead(FLAME_DIGITAL) == LOW);

  // Lower analog value means more infrared, i.e. a stronger flame
  Serial.print("level=");
  Serial.print(level);
  Serial.print("  digital=");
  Serial.println(tripped ? "FLAME" : "clear");

  hits = tripped ? hits + 1 : 0;
  if (hits >= ALARM_SAMPLES) {
    Serial.println("*** SUSTAINED FLAME DETECTED ***");
  }
  delay(200);
}

Applications

A ir flame sensor turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:

  • Fire detection in workshops, server cupboards and battery-charging areas
  • Flame-out supervision on gas burners and boilers
  • Fire-fighting robots that steer towards a candle in a maze
  • Safety interlocks that cut power or close a valve when flame is detected
  • Combustion monitoring on small engines and furnaces

Working with the Arduino Uno

The Arduino Uno is built around the ATmega328P and runs on 5 V logic with 2 KB of SRAM and 32 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.

The Uno runs at 5 V, so most hobby sensor modules connect directly with no level shifting.

With only 2 KB of SRAM, avoid large buffers and prefer the F() macro for constant strings.

The single hardware UART is shared with the USB connection, so heavy Serial printing competes with uploads.

Arduino Uno characteristicValueWhy it matters here
Logic voltage5 VMatches most hobby modules directly
ADC resolution10-bit (0–1023)Sets how finely an analog reading can be resolved
Analog inputsA0–A5 (six channels)Determines how many analog sensors can share the board
PWM outputsD3, D5, D6, D9, D10 and D11Needed for brightness, speed and tone control
I²C pinsA4 (SDA) and A5 (SCL)Fixed by hardware — wiring copied from another board may not match
Interrupt pinsD2 and D3 onlyRequired for counting fast or asynchronous events
Seriala single hardware UART shared with USBMonitor runs at 9600 baud by default

Troubleshooting

Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:

  • It triggers constantly outdoors or near a window — sunlight is the source. Shield the sensor or point it away from glazing.
  • It never triggers — the potentiometer is set too far; back it off until the LED just extinguishes with no flame present.
  • Range is only a few centimetres — these sensors are short-range by nature; 60–80 cm is realistic for a candle.
  • The analog value rises instead of falling near a flame — some carriers invert the output; verify the direction before setting thresholds.
  • Code written for an ESP board gives odd analog values — the Arduino Uno uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
  • An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Uno I²C is on A4 (SDA) and A5 (SCL).

Taking It Further on the Arduino Uno

Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Uno specifically:

The Uno’s shield ecosystem is its real advantage. Once the circuit works on a breadboard, a prototyping shield turns it into something permanent that still stacks with a data-logging or Ethernet shield without rewiring.

Logging to an SD card via a shield is the natural next step, since the Uno has no onboard storage and no network. Timestamp each reading with a DS3231 real-time clock so the log survives power cuts with correct times.

Because SRAM is limited to 2 KB, keep logged strings short and write them out immediately rather than buffering. Building a long String in memory is the most common cause of an Uno sketch that runs for hours and then freezes.

Notes and Practical Limits

Requiring several consecutive detections, as the sketch does, is the single most effective way to avoid false alarms. A camera flash or a passing headlight produces one sample; a real fire produces hundreds.

Never treat a hobby flame sensor as a substitute for a certified smoke or heat alarm. It is a useful trigger for automation and experiments, not a life-safety device.