meta data for this page
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| code:micropython_modul_flame_sensor [2026/05/14 11:25] – created vamsan | code: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 (//" | 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 (//" | ||
| - | The sample program is written for the [[sensor: | + | The sample program is written for the [[sensor: |
| <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(" | ||
| + | |||
| + | 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" | ||
| + | |||
| + | # Wait 200 milliseconds before the next sample | ||
| + | time.sleep(1) | ||
| + | </code> | ||
| + | |||
| + | **Output example** | ||
| + | |||
| + | < | ||
| + | ADC Value: 62495 | Voltage: 3.15V | Status: Safe / No Flame | ||
| + | ADC Value: | ||
| + | ADC Value: 63231 | Voltage: 3.18V | Status: Safe / No Flame | ||
| + | ADC Value: 62815 | Voltage: 3.16V | Status: Safe / No Flame | ||
| + | ADC Value: | ||
| + | ADC Value: | ||
| + | ADC Value: | ||
| + | ADC Value: | ||
| + | ADC Value: 63247 | Voltage: 3.18V | Status: Safe / No Flame | ||
| + | ADC Value: 63279 | Voltage: 3.19V | Status: Safe / No Flame | ||
| </ | </ | ||
| - | {{tag> | + | {{tag> |
| This page has been accessed for: Today: {{counter|today}}, | This page has been accessed for: Today: {{counter|today}}, | ||