meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
code:micropython_modul_flame_sensor [2026/05/14 11:25] – created vamsancode:micropython_modul_flame_sensor [2026/05/14 11:28] (current) vamsan
Line 2: Line 2:
 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//). 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 [[sensor:lm393#flame_sensor|LM393 Flame Sensor Module]].+The sample program is written for the [[sensor:lm393#flame_sensor|LM393 (KY-026) Flame Sensor Module]].
  
  
 <code python> <code python>
-code+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) 
 +</code
 + 
 +**Output example** 
 + 
 +<code> 
 +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
 </code> </code>
  
-{{tag>code! micropython 2026 RP2040_ETH}}+{{tag>code! micropython 2026 RP2040_ETH LM393 flame flame_sensor}}
  
 This page has been accessed for: Today: {{counter|today}}, Until now: {{counter|total}} This page has been accessed for: Today: {{counter|today}}, Until now: {{counter|total}}