This system monitors indoor air quality and environmental conditions using multiple sensors connected to a Raspberry Pi. It features real-time monitoring, data visualization, and automatic data logging to InfluxDB.
- ENS160 Air Quality Sensor (VOC, eCO2, AQI)
- BME280 Environmental Sensor (Temperature, Pressure, Humidity)
- TMP117 High-Precision Temperature Sensor
- SSD1306 OLED Display
- Temperature (°C)
- Humidity (%RH)
- Atmospheric Pressure (hPa)
- Air Quality Index (1-5 scale)
- Total Volatile Organic Compounds (TVOC) in ppb
- Equivalent CO2 (eCO2) in ppm
- Automatic range validation for all sensor readings
- Sensor health tracking and error counting
- Fresh reading detection
- Operational status monitoring
- Error threshold monitoring
- Configurable measurement intervals
- RAM-based data caching
- Batch data transmission to InfluxDB
- Automatic retry mechanism for failed transmissions
- Configurable transmission intervals
Multiple display pages showing:
- Main readings (Temperature, Humidity, Pressure, AQI)
- Detailed air quality data (AQI, TVOC, eCO2)
- Temperature history graph
- Sensor health status
- Environmental recommendations
- Real-time air quality scoring
- Dynamic recommendations based on:
- CO2 levels
- TVOC levels
- Humidity conditions
- UBA (German Federal Environmental Agency) guideline compliance
-
Sensor Reading
- Temperature compensation from TMP117
- Humidity compensation from BME280
- ENS160 air quality measurements
-
Data Validation
- Range checking for all values
- Operational status verification
- Sensor health monitoring
-
Data Processing
- Environmental score calculation
- Recommendation generation
- History tracking for graphing
-
Data Storage
- RAM-based circular buffer
- Batch processing for InfluxDB
- Configurable cache size
-
Data Display
- OLED display updates
- Console logging
- Multiple information pages
graph TD
subgraph Sensors
TMP[TMP117 Temperature] --> TC[Temperature Compensation]
BME[BME280 Environmental] --> HC[Humidity Compensation]
TC & HC --> ENS[ENS160 Air Quality]
end
subgraph Processing
ENS --> VLD[Data Validation]
VLD --> Cache[RAM Cache]
Cache --> |Batch| IDB[InfluxDB]
VLD --> |Real-time| DISP[OLED Display]
end
subgraph Analysis
VLD --> ENV[Environmental Score]
ENV --> REC[Recommendations]
REC --> DISP
end
subgraph Monitoring
VLD --> Health[Health Monitor]
Health --> Error[Error Counter]
Error --> Status[Status Display]
Status --> DISP
end
- AQI: 1-5 (UBA Guidelines)
- 1: Excellent
- 2: Good
- 3: Moderate
- 4: Poor
- 5: Unhealthy
- TVOC: 0-65,000 ppb
- eCO2: 400-65,000 ppm
- Temperature: -40°C to +85°C
- Humidity: 0-100% RH
- Pressure: 300-1100 hPa
- Range: -55°C to +150°C
- Accuracy: ±0.1°C (0°C to +65°C)
+----------------+
|Temp: 23.5C |
|Humid: 45.2% |
|Press: 1013.2 |
|Air Quality: |
|Excellent |
+----------------+
+----------------+
|Air Quality Data|
|AQI: 1/5 |
|TVOC: 250ppb |
|CO2: 800ppm |
+----------------+
+----------------+
|Temp History |
| ___ |
| / \ |
|___/ \_____|
|L:22.1 H:24.3 |
+----------------+
+----------------+
|Sensor Health |
|✓ temp_sensor |
|✓ air_quality |
|✓ atmospheric |
+----------------+
+----------------+
|Air Quality |
|Level: Good |
|Open windows |
|for fresh air |
+----------------+
Measurement: sensorReading
Tags:
- sensor: "PiicoDevSensors"
- location: <room_name>
Fields:
- temperature: float
- humidity: float
- pressure: float
- aqi: integer
- tvoc: integer
- eco2: integer
- aqi_rating: string
- eco2_rating: string
- sensor_status: string
Timestamp: unix_timestamp
Key configurable parameters:
- Measurement intervals
- Display pages
- InfluxDB settings
- Cache sizes
- Health check thresholds
- Sensor ranges
- Environmental thresholds
- Graceful degradation with sensor failures
- Last known good value retention
- Automatic recovery attempts
- Comprehensive logging
- Signal handling for clean shutdown
- PiicoDev sensor libraries
- InfluxDB client
- Python standard library
# Required system packages
sudo apt-get update
sudo apt-get install -y python3-pip python3-smbus i2c-tools
# Enable I2C interface
sudo raspi-config # Navigate to Interface Options -> I2C -> Enable
# Verify I2C devices
sudo i2cdetect -y 1
Create a requirements.txt:
influxdb-client>=1.24.0
PiicoDev>=1.4.0
Install dependencies:
pip3 install -r requirements.txt
- Install InfluxDB on your server
- Create a bucket named "sensorData"
- Generate an API token with write access
- Set environment variable:
export INFLUXDB_TOKEN="your-token-here"
Edit the CONFIG dictionary in the script to match your setup:
CONFIG = {
'MEASUREMENT_INTERVAL_MS': 1000, # Adjust sampling rate
'INFLUXDB': {
'URL': "http://your-influx-server:8086",
'ORG': "your-org",
'BUCKET': "sensorData",
},
'SENSOR_LOCATION': "room-name" # Identify sensor location
}
python3 ens160AirQualitySensor.py
Add to system startup (optional):
# Create service file
sudo nano /etc/systemd/system/air-quality.service
# Add the following content:
[Unit]
Description=Air Quality Monitoring
After=network.target
[Service]
Environment=INFLUXDB_TOKEN=your-token-here
ExecStart=/usr/bin/python3 /path/to/ens160AirQualitySensor.py
WorkingDirectory=/path/to/script/directory
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
# Enable and start service
sudo systemctl enable air-quality
sudo systemctl start air-quality
-
Sensor Not Found
- Check I2C connections
- Verify I2C addresses:
sudo i2cdetect -y 1
- Check power supply
-
InfluxDB Connection Errors
- Verify network connectivity
- Check token permissions
- Confirm bucket exists
-
Display Issues
- Verify I2C address conflicts
- Check display orientation
- Validate power supply
The script logs to stdout with timestamp and level:
2023-XX-XX HH:MM:SS - INFO - Starting sensor monitoring...
2023-XX-XX HH:MM:SS - INFO - All sensors initialized successfully
Monitor logs with:
# If running as service
journalctl -u air-quality -f
# If running directly
python3 ens160AirQualitySensor.py | tee sensor.log
- Check sensor readings against known good values
- Monitor error counts in logs
- Verify InfluxDB data ingestion
- Clean display screen if needed
The ENS160 sensor features automatic baseline correction. For best results:
- Allow 24-48 hours of operation for initial baseline
- Ensure regular fresh air exposure
- Maintain stable temperature and humidity
Feel free to submit issues and enhancement requests!
The system requires the ENS160 sensor to report "operating ok" status before recording data, ensuring accuracy of air quality measurements.
- Metal oxide (MOX) sensor technology
- Built-in temperature and humidity compensation
- Automatic baseline correction
- UBA-compliant air quality ratings
-
Excellent (1)
- Ideal indoor air quality
- No action needed
- Typical in well-ventilated spaces
-
Good (2)
- Normal indoor conditions
- Continue regular ventilation
- Monitor for changes
-
Moderate (3)
- Some air quality deterioration
- Increase ventilation
- Check for pollution sources
-
Poor (4)
- Significant air quality issues
- Open windows immediately
- Activate air purifiers if available
- Identify and remove pollution sources
-
Unhealthy (5)
- Severe air quality problems
- Evacuate if necessary
- Maximum ventilation required
- Professional assessment recommended
-
Low (0-500 ppb)
- Normal indoor conditions
- No action needed
-
Moderate (500-2000 ppb)
- Increased VOC presence
- Improve ventilation
- Check for new furnishings or cleaning products
-
High (2000-5000 ppb)
- Significant VOC levels
- Identify and remove sources
- Consider air purification
-
Very High (>5000 ppb)
- Immediate action required
- Maximum ventilation
- Evacuate if necessary
-
400-800 ppm
- Excellent air quality
- Normal outdoor to indoor levels
-
800-1000 ppm
- Good air quality
- Typical occupied indoor space
-
1000-1500 ppm
- Fair air quality
- Increase ventilation recommended
-
1500-2000 ppm
- Poor air quality
- Open windows
- Check ventilation systems
-
>2000 ppm
- Unacceptable air quality
- Immediate ventilation required
- Check for CO2 sources
-
Sensor Placement
- Avoid direct sunlight
- Keep away from direct airflow
- Place at breathing height
- Maintain distance from walls
-
Baseline Calibration
- Allow initial 24-48 hour baseline period
- Regular exposure to fresh air
- Avoid placement near pollution sources
-
Environmental Conditions
- Maintain stable temperature
- Control humidity levels
- Avoid rapid environmental changes
-
Maintenance
- Regular dust cleaning
- Periodic baseline recalibration
- Validation against known conditions
Condition | Immediate Action | Long-term Action
-------------------|----------------------|------------------
High TVOC | Open windows | Find VOC sources
High eCO2 | Increase ventilation | Check HVAC
Poor AQI | Air purification | Environmental audit
High Humidity | Dehumidification | Check for leaks
Low Humidity | Use humidifier | Monitor heating