lamaPLC: MicroPython Flame Sensor Modul

This MicroPython code reads the infrared analogue signal from an IR module (ignoring the DI signal), and outputs the converted analogue value read, as well as generating its own digital signal (β€œFLAME DETECTED! πŸ”₯”) based on the captured threshold value (FLAME_THRESHOLD).

The sample program is written for the LM393 (KY-026) Flame Sensor Module.

import machine
import time
 
# Configure ADC0 on GPIO26
flame_sensor = machine.ADC(26)
 
# Calibration threshold (0-65535)
# Most analog flame sensors output a LOWER voltage when a flame is detected.
# Adjust this value based on your ambient light conditions.
FLAME_THRESHOLD = 50000 
 
print("Starting Flame Sensor Monitoring...")
 
while True:
    # Read the 16-bit analog value (range: 0 to 65535)
    raw_value = flame_sensor.read_u16()
 
    # Calculate the corresponding voltage (based on 3.3V reference)
    voltage = (raw_value * 3.3) / 65535
 
    # Evaluate the sensor readings
    # Typical flame sensors pull the analog output LOW in the presence of fire.
    if raw_value < FLAME_THRESHOLD:
        status = "FLAME DETECTED! πŸ”₯"
    else:
        status = "Safe / No Flame"
 
    # Print results to the serial console
    print(f"ADC Value: {raw_value:5d} | Voltage: {voltage:.2f}V | Status: {status}")
 
    # Wait 200 milliseconds before the next sample
    time.sleep(1)

Output example

ADC Value: 62495 | Voltage: 3.15V | Status: Safe / No Flame
ADC Value:  2880 | Voltage: 0.15V | Status: FLAME DETECTED! πŸ”₯
ADC Value: 63231 | Voltage: 3.18V | Status: Safe / No Flame
ADC Value: 62815 | Voltage: 3.16V | Status: Safe / No Flame
ADC Value:  2624 | Voltage: 0.13V | Status: FLAME DETECTED! πŸ”₯
ADC Value:  2528 | Voltage: 0.13V | Status: FLAME DETECTED! πŸ”₯
ADC Value:  2912 | Voltage: 0.15V | Status: FLAME DETECTED! πŸ”₯
ADC Value:  3760 | Voltage: 0.19V | Status: FLAME DETECTED! πŸ”₯
ADC Value: 63247 | Voltage: 3.18V | Status: Safe / No Flame
ADC Value: 63279 | Voltage: 3.19V | Status: Safe / No Flame

This page has been accessed for: Today: 2, Until now: 2