Flame Sensor Interfacing with PIC16F877A

This article is a continuation of the series of tutorials on the PIC16F877A Microcontroller. The aim of this series is to provide easy and practical examples that anyone can understand. In the previous tutorial, we have interfaced the Touch sensor with PIC16F877A. In this tutorial, we are going to discuss Flame Sensor Interfacing with PIC16F877A.


Before starting this tutorial we should know the below topics. If you know already, please go further.

Components Required

  • PIC16F877A Development Board
  • Flame Sensor
  • LCD Module (To print the Sensor output)


Fire is one of the most dangerous events possible; somewhere in the world, one occurs every minute of every day. While fire can be our friend in some instances, it can be our worst enemy when it’s uncontrolled and allowed to continue through a building. Fire is, of course, destructive, and the smoke from a fire creates a toxic, dangerous atmosphere. The rapid detection of a fire and its control can save several thousand lives, thousands of injuries, and millions of dollars in property loss each year.

The flame is the visible portion of the fire. So if we find the flame, then we can also find the fire.

Characteristics of flame

All flames have certain characteristics in common that include:

  • Production of heat
  • Expansion of gases
  • Production of the by-product of combustion
  • Emission of light (infrared or ultraviolet)
  • Ionization of the atmosphere in and around the flame

Flame detection systems have been developed to incorporate several of these characteristics.

Flame Detector

flame detector is a sensor designed to detect and respond to the presence of a flame or fire, allowing flame detection.

Today’s flame detectors utilize optical technologies to detect flames. Flames are known to emit electromagnetic radiation in the infrared (IR), visible light, and ultraviolet (UV) wavelengths depending on the fuel source.

Optical flame sensors are divided into many groups depending on which range of the total radiation band they are designed to detect:

  • Ultraviolet detector
  • Near IR array
  • Infrared
  • Infrared thermal cameras
  • UV/IR
  • IR/IR flame detection
  • IR3 flame detection
  • Visible sensors

Flame detector using Infrared

Since more than 90% of the flame’s total radiation is infrared, these detectors receive ample radiation of quite high intensity and will operate with either very weak or very hot flames. So in this tutorial, we are going to use an IR flame detector.

Flame sensors are available in the market in two types one having three pins and the other having four pins respectively. Both of the sensors can be easily interfaced with any microcontroller. I am using the three-pin flame sensor in this tutorial.

Note: If you are using a 4-Pin sensor, you need to use D0 Pin to work with this example.

A flame sensor can detect fire or any other light sources whose wavelength is in the range of 760nm to 1100nm. This device consists of an IR sensor, an LED for indication, an operational amplifier circuit, and a potentiometer. The device is sensitive to flame so when it detects the flame it turns on its LED to show any indication. The sensitivity of the flame sensor can be adjusted according to the requirements. It can be used at different places e.g. in offices, homes, institutions, industrial applications.

The PCB of this electronic circuit has a potentiometer. The Sensitivity of the Digital pin can be varied using the potentiometer.

Flame Sensor Interfacing with PIC16F877A


Flame Sensor

  • Vcc – 5v
  • GND – Ground
  • D0 – RD0 (PORTD.0)


  • RS – RC0
  • RW – RC1
  • EN –RC2
  • Data Lines – PORTB

Flame Sensor Interfacing with PIC16F877A

Source Code

If it is detecting any flame in front of this sensor, LCD will display “Flame Detected”.

#define FLAME RD0                  //Flame sensor Output is connected at PORTD.0
#define rs RC0
#define rw RC1
#define en RC2
#define delay for(i=0;i<1000;i++)
int i;
void lcd_init();
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);
void main()
    TRISD=0xff;                         //Port D act as Input
    show("   EmbeTronicX  ");
    while(1) {
        if(FLAME) {
            show("Flame Detected");
        } else {
            show("                ");
void lcd_init()
void cmd(unsigned char a)
void dat(unsigned char b)
void show(unsigned char *s)

Note: In our tutorial, we are using the 3-pin sensor. Only Digital output is available in this sensor. If you want to use the 4-pin sensor, you can use the 4-pin sensor’s D0 Pin. But somebody may want to use an A0 pin in a 4-pin sensor. In that case, you cannot use this example. You need to use ADC for that case since it is not digital output.

In our next tutorial, we will see how to interface the Rain detecting sensor with PIC16F877A.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
STM32F7 Bootloader TutorialsRaspberry PI Pico Tutorials
STM32F103 Bootloader TutorialsRT-Thread RTOS Tutorials
Zephyr RTOS Tutorials - STM32Zephyr RTOS Tutorials - ESP32
AUTOSAR TutorialsUDS Protocol Tutorials
Product ReviewsSTM32 MikroC Bootloader Tutorial
VHDL Tutorials
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Table of Contents