Smart Indoor Air Quality Monitor With Auto Ventilation Using Raspberry Pi 5
by Daniel DSouza in Circuits > Raspberry Pi
71 Views, 0 Favorites, 0 Comments
Smart Indoor Air Quality Monitor With Auto Ventilation Using Raspberry Pi 5
Indoor air pollution is one of the most overlooked health risks today. From cooking fumes and dust to volatile organic compounds (VOCs), the air inside our homes can often be more polluted than outdoor air. This is where a smart indoor air quality monitor becomes essential.
In this project, you’ll build a smart indoor air quality monitor with auto ventilation using Raspberry Pi 5, capable of detecting harmful gases and automatically controlling a fan when air quality drops.
Why This Project Matters
- Real-time indoor AQI monitoring with automation
- Automatically triggers ventilation when pollution rises
- Helps build a smart home air quality control system
- Ideal for homes, labs, offices, and IoT enthusiasts
This is not just a simple sensor project; this is a complete IoT based air quality monitoring system with automation that you can expand into a full smart home solution.
Project Overview
This air quality monitoring system using Raspberry Pi works in a simple but powerful pipeline:
- Sensors collect data
- Raspberry Pi processes data
- AQI is calculated
- Decision logic triggers relay
- Fan turns ON/OFF automatically
Workflow
Sensor → Raspberry Pi → AQI Calculation → Decision → Relay → Fan
Supplies
Core Components
- Raspberry Pi 5
- The brain of the system for processing and automation
- MQ135 Gas Sensor
- Detects CO₂, NH₃, alcohol, benzene, smoke
- BME680 Sensor (Optional but Recommended)
- Measures temperature, humidity, pressure, VOCs
- Relay Module (5V)
- Controls fan automatically
- DC Fan / Exhaust Fan
- For ventilation
Additional Components
- Breadboard
- Jumper wires
- Power supply (5V 3A for Raspberry Pi)
- Resistors (if needed)
- ADC module (like MCP3008 for MQ135 analog output)
System Architecture
Before jumping into wiring, it's important to understand how your smart indoor air quality monitor actually works internally. Think of this step as building the “brain map” of your system.
How the System Thinks
Your Raspberry Pi 5 IoT air quality system operates in a continuous loop:
- Data Collection Layer
- The MQ135 sensor continuously detects gases like CO₂, ammonia, and smoke.
- The BME680 (if used) adds environmental data like humidity and VOC levels.
- Signal Conversion Layer
- MQ135 outputs analog signals.
- Raspberry Pi cannot read analog signals directly.
- MCP3008 converts analog → digital signals via SPI communication.
- Processing Layer
- Raspberry Pi reads sensor values every few seconds.
- It processes the data and applies AQI logic.
- Decision Layer
- If air quality crosses a threshold → trigger action.
- Actuation Layer
- Relay module turns ON/OFF the fan.
This creates an auto ventilation system using Raspberry Pi.
Real-Time Loop
This process repeats every 2–5 seconds, enabling indoor AQI monitoring with automation.
Required Hardware Setup
Now let’s physically assemble your Raspberry Pi air quality sensor project.
Step-by-Step Assembly
1. Positioning Components
- Place Raspberry Pi on a stable surface
- Keep breadboard close to minimize wire clutter
- Ensure proper ventilation space for testing
2. Power Setup
- Use a 5V 3A power adapter
- Do NOT power sensors from unstable sources
3. Sensor Placement
- Keep MQ135 exposed to air (not enclosed)
- Avoid placing it near heat sources
4. Relay Setup
- Place relay module away from Pi to avoid electrical noise
- Use proper insulation if working with AC loads
Safety Guidelines
- If you're a beginner, use a DC fan instead of AC
- Never touch exposed wires when powered
- Double-check connections before switching ON
Raspberry Pi OS Installation
This step sets up the software environment for your IoT based air quality monitoring system.
Full Installation Process
1. Flash OS
- Download Raspberry Pi Imager
- Select:
- OS → Raspberry Pi OS (64-bit recommended)
- Storage → Your SD card
2. Advanced Settings (Important)
- Enable SSH (optional)
- Set WiFi credentials
- Set username/password
3. First Boot
- Insert SD card into Pi
- Connect monitor, keyboard, mouse
- Power ON
4. Enable Interfaces
Navigate to:
- Interface Options → Enable SPI
- Interface Options → Enable I2C
Update System
Tip
Always update your system before installing libraries to avoid compatibility issues.
Official Guide: https://www.raspberrypi.com/documentation/computers/getting-started.html
Sensor Connections
MQ135 → MCP3008 → Raspberry Pi
MQ135 Connections:
- VCC → 5V
- GND → GND
- AOUT → CH0 (MCP3008)
MCP3008 → Pi:
- VDD → 3.3V
- VREF → 3.3V
- AGND/DGND → GND
- CLK → GPIO11
- DOUT → GPIO9
- DIN → GPIO10
- CS → GPIO8
BME680 (Optional but Powerful)
- Uses I2C (simpler wiring)
- Connect:
- SDA → GPIO2
- SCL → GPIO3
MCP3008 Datasheet: https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf
Installing Required Libraries
Now we prepare the software tools for your Raspberry Pi 5 based smart home air quality control project.
Install Libraries
Verify SPI
You should see:
Why These Libraries?
- spidev → Reads analog values via MCP3008
- RPi.GPIO → Controls relay
- bme680 → Reads environmental data
Writing the Python Code
Now we build the logic for your IoT air quality monitoring system with automatic fan control.
Code Breakdown
1. Initialize SPI
- Connects to MCP3008
2. Read Sensor Data
- Converts analog → digital values
3. Process Data
- Converts raw values into AQI
4. Control Output
- Turns fan ON/OFF
Key Functions
Read sensor values
Calculate AQI
Control relay
Tip
Test each part individually before combining everything.
AQI Calculation Logic
AQI is the heart of your indoor air pollution monitoring project.
Range Category
0–200 Good
200–400 Moderate
400+ Unhealthy
Tip
- Convert MQ135 readings → PPM
- Use standard AQI formulas for accuracy
Relay & Fan Automation Setup
This is where your smart home air quality control system becomes truly “smart”.
How It Works
- AQI = Good → Fan OFF
- AQI = Moderate → Optional ON
- AQI = Unhealthy → Fan ON
Relay Logic
- GPIO HIGH → Relay ON → Fan ON
- GPIO LOW → Relay OFF → Fan OFF
Tip
Some relays are active LOW, so test before finalizing.
Testing & Calibration
Testing ensures your Raspberry Pi air quality sensor project works reliably.
Testing Methods
- Use incense sticks or perfume spray
- Observe sensor spikes
- Check if fan activates
Calibration Tips
- Let MQ135 warm up for 24–48 hours
- Record baseline values
- Adjust thresholds accordingly
Final Output & Use Case
What You’ll See
- Real-time sensor values in terminal
- AQI classification updates
- Fan automatically turning ON/OFF
Complete Python Code
External Resources
- Raspberry Pi Docs: https://www.raspberrypi.com/documentation/
- MQ135 Guide: https://components101.com/sensors/mq135-gas-sensor-for-air-quality
- BME680 Library: https://github.com/adafruit/Adafruit_CircuitPython_BME680
- MCP3008 Datasheet: https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf
Future Improvements
- Mobile App (Blynk / Firebase)
- Cloud Dashboard (MQTT, Node-RED)
- AI-based AQI prediction
Conclusion
You’ve successfully built a smart indoor air quality monitor with auto ventilation using Raspberry Pi 5—a complete smart home air quality control system with real-world applications.
This project is a perfect combination of:
- IoT
- Automation
- Environmental monitoring