Overview
Learn how to use the KY-026 flame sensor with a Raspberry Pi Pico to detect flame or strong infrared light. This project is useful for fire alarms, safety monitoring, and simple warning systems.
Instructions
Step by step
1. Connect the KY-026 VCC pin to 3.3V.
2. Connect the KY-026 GND pin to GND.
3. Connect the KY-026 DO pin to GP18.
4. Connect the KY-026 AO pin to GP26 if you want to read flame intensity.
5. Run the code and open the Serial/console output.
6. Click or adjust the flame sensor in the simulator.
7. When flame is detected, the output should print "Flame detected!".
8. When no flame is detected, the output should print "No flame".
Code
Source code
from machine import Pin, ADC
import utime
flame_digital = Pin(18, Pin.IN)
flame_analog = ADC(Pin(26))
while True:
digital_value = flame_digital.value()
analog_value = flame_analog.read_u16()
if digital_value == 0:
print("Flame detected! Level:", analog_value)
else:
print("No flame. Level:", analog_value)
utime.sleep(0.5)
Related