Introduction:
This experiment involves detecting the presence of a flame using a flame sensor connected to a Raspberry Pi Pico microcontroller. By measuring the analog output of the flame sensor, the program determines whether a flame is present, providing a "High" or "Low" indication based on the sensor’s readings.
Scope:
This experiment is designed for embedded systems enthusiasts and students to understand how analog sensors can interface with microcontrollers. It also demonstrates how to process sensor data and implement a real-world application where flame detection might be necessary, such as fire safety systems.
Prerequisite:
3.1. Hardware:
Pico microcontroller
Flame sensor module
Breadboard
Jumper wires
USB cable (to connect the computer)
3 .2. Software:
Thonny Software(For micro python)
MicroPython firmware installed on Raspberry Pi Pico
ubuntu Terminal(For embedded C)
CMake,Pico SDK,GNU Arm Embedded Toolchain,WSL.
Connection Details:
Flame Sensor Output: Connect the analog output pin of the flame sensor to GPIO 26 (ADC0) on the Raspberry Pi Pico.
Power: Connect the VCC of the flame sensor to the 3.3V pin and GND to the
GND pin on the Pico.
UART Serial Console: Use a micro-USB cable to connect the Pico to the PC, then open PuTTY and select the correct COM port and baud rate (115200).

Working Principle:
The flame sensor detects infrared radiation emitted by flames and outputs an analog voltage. The Raspberry Pi Pico reads this voltage through its ADC (Analog-to-Digital Converter) pin. If the value is above a defined threshold, it indicates flame presence ("High"); otherwise, it indicates no flame ("Low").
The Flame sensor is a sensor that can detect the presence of fire or flames. The flame sensor works based on infrared radiation. The IR photodiode will detect the IR radiation from any hot body. This value is then compared with a set value. Once the radiation reaches the threshold value, the sensor will change its output accordingly. It is widely used in fire detection systems in homes and industries.
The Flame sensor works on the principle of infrared (IR) detection. The sensor has an IR receiver that detects the IR radiation emitted by flames. When fire burns it emits a small amount of Infra-red light, this light will be received by the Photodiode (IR receiver) on the sensor module. Then we use an Op-Amp to check for a change in voltage across the IR Receiver, so that if a fire is detected the output pin (DO) will give 0V(LOW), and if the is no fire the output pin will be 5V(HIGH).
Specification
Supply Voltage: 3.3V - 5V
PCB Size: 31 x 14mm
Output Signal Type: DO and AO
Detection Angle: 60 degrees
Pinout
VCC: This is the positive power supply input from the main control.
GND: Ground connection.
DO: Digital output. It indicates the presence of a flame. When the infrared radiation exceeds the threshold value (set by the potentiometer), DO becomes LOW; otherwise, it remains HIGH.
AO: Analog output. It generates an output voltage that is inversely proportional to the intensity of infrared radiation (flame size). Therefore, higher infrared radiation will result in a lower voltage, while lower infrared radiation will result in a higher voltage.
Application code:
MicroPython:
from machine import ADC, Pin
from time import sleep
flame_sensor = ADC(Pin(26)) # GPIO26 (ADC0)
FLAME_THRESHOLD = 1000 # Adjust based on your sensor
while True:
flame_value = flame_sensor.read_u16() # Reads 0-65535
if flame_value > FLAME_THRESHOLD:
print("Flame Detected: High")
else:
print("No Flame: Low")
sleep(0.5) # Delay 500 ms
Embedded C:
#include "pico/stdlib.h"
#include "hardware/adc.h"
#include <stdio.h>
#define FLAME_SENSOR_PIN 26 // ADC0 (GPIO26)
#define FLAME_THRESHOLD 1000 // Adjust this value based on sensor readings
int main() {
stdio_init_all();
adc_init();
// Initialize GPIO for ADC and select input
adc_gpio_init(FLAME_SENSOR_PIN);
adc_select_input(0);
while (1) {
uint16_t flame_value = adc_read();
if (flame_value > FLAME_THRESHOLD) {
printf("Flame Detected: High\n");
} else {
printf("No Flame: Low\n");
}
sleep_ms(500);
}
return 0;
}
Hardware Image:

Output:
Upon execution:
When a flame is detected, the output will show "Flame Detected: High".

Video Demonstration:
Appendix:
Common CMakeLists:
cmake_minimum_required(VERSION 3.12)
# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)
project(pico_experiments C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()
# Initialize the SDK
pico_sdk_init()
add_compile_options(-Wall
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # we have some for the docs that arent called
)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wno-maybe-uninitialized)
endif()
# Hardware-specific examples in subdirectories:
add_subdirectory(expt_10_LCD)
CMakeLists:
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(flame_detection_project)
pico_sdk_init()
add_executable(flame_detection
flame_detection.c
)
target_link_libraries(flame_detection pico_stdlib hardware_adc)
pico_enable_stdio_usb(flame_detection 1)
pico_add_extra_outputs(flame_detection)
References:
| # | Topic | Date & time | Action |
|---|
0% Completed (0/1)