Flame Presence Sensor with Smart Pi One¶
In this guide, we will demonstrate how to read the values from a flame presence sensor connected to the Smart Pi One, using the SmartPi-GPIO library.
We will cover the following methods: - CLI commands - Python script
Required Materials¶
- Smart Pi One
- Flame presence sensor (e.g., DFRobot DFR0090 or similar)
- Connecting wires
- Breadboard (optional for easier connections)
Wiring Diagram¶
The flame presence sensor typically has three pins: VCC, GND, and DOUT (digital output).
- VCC connects to 5V (Pin 1).
- GND connects to Ground (Pin 6).
- DOUT connects to GPIOG11(Pin 7) to read the presence of flame.
Pin Number | Pin Name | Function |
---|---|---|
2 | 5V | Power Supply |
7 | GPIOG11 | Flame Sensor Output (D0) |
6 | GND | Ground |
Prerequisites: Configuration of smartpi-gpio¶
To install SmartPi-GPIO on your Smart Pi One, follow these steps:
- Update system:
sudo apt update
sudo apt-get install -y python3-dev python3-pip libjpeg-dev zlib1g-dev libtiff-dev
sudo mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/EXTERNALLY-MANAGED.old
- Clone the repository:
- Install the library:
- Activate GPIO interfaces:
Reading Values via CLI¶
You can read the values from the flame presence sensor using the CLI.
Steps:¶
- Configure the pin for digital input:
- Read the value from the flame sensor:
- Example to read and display values continuously:
Use a loop to read the state of the flame sensor and print its value:
This will display the current value read by the flame sensor every second.
Using Python¶
Reading Values with Python¶
With SmartPi-GPIO and Python, you can write a simple script to read the value from the flame presence sensor.
Steps:¶
- Create a Python file:
- Write the following code:
from smartpi_gpio.gpio import GPIO
import time
# Initialize GPIO instance
gpio = GPIO()
# GPIO pin number for the flame sensor (GPIO7)
flame_sensor_pin = 7
# Configure the pin as input
gpio.set_direction(flame_sensor_pin, "in")
print("Reading values from the flame presence sensor...")
while True:
# Read the value from the flame sensor
value = gpio.read(flame_sensor_pin)
print(f"Flame Sensor Value: {value}")
time.sleep(1) # Read every second
-
Save and exit (
CTRL+X
,Y
, andEnter
). -
Run the Python script:
This will continuously display the current value read by the flame presence sensor every second.