This project uses a Raspberry Pi 3 Model B and an SDS 011 sensor to monitor air quality by measuring both PM2.5 and PM10 values. The sensor provides real-time data on air pollution, and the system logs this data to Adafruit IO. Additionally, PM2.5 and PM10 values are sent hourly to a Telegram Channel with color-coded air quality indicators to notify users about current air quality levels.
- Introduction
- Hardware Requirements
- Software Setup
- Installation
- Usage
- Telegram Integration
- Adafruit IO Integration
- Supervisor Setup
- License
The SDS 011 Sensor is a reliable air quality sensor developed by Nova Fitness, capable of detecting particulate matter (PM) with a diameter of less than 2.5 micrometers (PM2.5). This project gathers air quality data using the sensor and a Raspberry Pi 3 Model B. The data is:
- Logged to Adafruit IO for tracking air quality over time.
- Sent to a Telegram Channel every hour, providing timely updates on air quality conditions.
PM2.5 is a widely accepted indicator of air quality, and this project follows guidelines set by the World Health Organization (WHO), which recommends a PM2.5 value not exceeding 10 μg/m³ annually or 25 μg/m³ over 24 hours.
- Raspberry Pi 3 Model B
- SDS 011 Air Quality Sensor
- USB to Serial converter (for connecting the SDS 011 to the Raspberry Pi)
- MicroSD card (8GB+)
- Power supply for Raspberry Pi
- Internet connection (Ethernet or Wi-Fi)
You will need the following software installed on your Raspberry Pi:
- Raspbian OS (or Raspberry Pi OS)
- Python 3 (with
pip
installed) - Adafruit IO Python Client
- python-telegram-bot library
- Supervisor for running the script as a background service
To install the necessary Python libraries:
sudo apt update
sudo apt install python3-pip
python3 -m venv venv
source venv/bin/activate
pip3 install setuptools pyserial adafruit-io python-telegram-bot schedule python-dotenv
-
Clone the Repository:
Clone the repository to your Raspberry Pi:
git clone https://github.com/wildlifechorus/pm25_monitor.git cd pm25_monitor
-
Configure the
.env
File:Create a
.env
file in the root directory and add the following:AIO_USER_NAME=your_adafruit_username AIO_KEY=your_adafruit_key TELEGRAM_TOKEN=your_telegram_bot_token CHANNEL_ID=@your_telegram_channel_id
Make sure to replace placeholders with your own credentials.
-
Test the Script:
Run the script to make sure it works:
python3 pm25_monitor.py
-
Supervisor Setup:
Configure Supervisor to run the script automatically. See Supervisor Setup for details.
Once the script is running, it will:
- Collect PM2.5 and PM10 data from the SDS 011 sensor every 10 seconds.
- Send the PM2.5 and PM10 data to Adafruit IO for real-time logging.
- Send a message with both PM2.5 and PM10 values to your Telegram Channel every hour, along with color-coded air quality status (🟢 Good, 🟡 Moderate, 🔴 Unhealthy).
To send PM2.5 data to a Telegram channel:
- Create a Telegram bot using BotFather.
- Add the bot to your channel as an admin.
- Obtain the bot token and channel ID, and add them to your
.env
file.
You will need to create an account on Adafruit IO and set up feeds for logging PM2.5 values.
- Feed 1: For PM2.5 values (
air-quality-pm-2-5
) - Feed 2: For PM10 values (
pm-ten
)
Add your Adafruit IO credentials in the .env
file:
AIO_USER_NAME=your_adafruit_username
AIO_KEY=your_adafruit_key
We use Supervisor to manage the script as a background process, ensuring that it starts automatically and restarts on failure.
-
Install Supervisor:
sudo apt install supervisor
-
Create a configuration file for the script:
sudo nano /etc/supervisor/conf.d/pm25_monitor.conf
Add the following content:
[program:pm25_monitor] command=/home/pi/pm25_monitor/venv/bin/python3 /home/pi/pm25_monitor/pm25_monitor.py directory=/home/pi/pm25_monitor autostart=true autorestart=true startsecs=10 stdout_logfile=/var/log/pm25_monitor.log stderr_logfile=/var/log/pm25_monitor_err.log user=pi
-
Update and start Supervisor:
sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start pm25_monitor
Your script will now run in the background and restart automatically if it crashes.
This project is licensed under the MIT License - see the LICENSE file for details.