This project is designed to create an environment for testing PM2.5 measurement devices by maintaining the PM2.5 concentration in a room at a specified level. The system uses HTTP communication to monitor and adjust the PM2.5 levels by controlling fans through a MAX31790 6-channel fan controller.
The system monitors PM2.5 levels and adjusts fan speeds to maintain the air quality in a room. It consists of several components implemented in different C++ files, each responsible for specific functionalities, such as data logging, PM sensor communication, and HTTP-based data retrieval. The system features automatic operation with a 5-hour cycle using world standard PM2.5 values.
- Automatic 5-Hour Cycle: Automatically starts after 60 seconds and runs through a 5-hour PM2.5 generation cycle
- World Standard PM2.5 Values: Uses standardized target values: 5, 10, 25, 35, 50 μg/m³
- PM2.5 Monitoring: Continuously measures the PM2.5 level in the room using a PMS5003 sensor
- Intelligent Fan Control: Uses MAX31790 6-channel PWM fan controller for precise speed control
- HTTP Communication: Retrieves real-time data from AirGradient API and posts sensor data
- WiFi Connectivity: Stable WiFi connection with proper initialization sequence
- Real-time Logging: Comprehensive logging system for monitoring and debugging
- Manual Override: Serial commands for manual start/stop control
- Calculator.cpp / Calculator.h: Contains the logic for calculating the appropriate fan speed based on the current PM2.5 level and target level, including inlet concentration calculations
- MyLog.cpp / MyLog.h: Provides comprehensive logging functionality for system events, errors, and PM2.5 measurements with different log levels (DEBUG, INFO, ERROR)
- PMS.cpp / PMS.h: Implements the interface to the PMS5003 PM2.5 sensor, handling data acquisition and providing real-time PM readings
- main.cpp: The main application controlling the entire system including:
- WiFi connection management
- HTTP communication tasks
- Automatic 5-hour cycle control
- Fan controller task with MAX31790
- Serial command handling
- Multi-task coordination using FreeRTOS
The system runs a fully automated 5-hour cycle:
- Hour 1: Target PM2.5 = 5 μg/m³
- Hour 2: Target PM2.5 = 10 μg/m³
- Hour 3: Target PM2.5 = 25 μg/m³
- Hour 4: Target PM2.5 = 35 μg/m³
- Hour 5: Target PM2.5 = 50 μg/m³
After completing the cycle, the system stops and requires manual restart or ESP32 reset.
- API Data Retrieval: Gets PM2.5 data from 5 reference sensors via AirGradient API
- Data Posting: Sends local sensor data to monitoring servers every minute
- Weighted Average: Calculates room average from multiple sensor readings
- ESP32 Development Board: uPesy ESP32 Wrover DevKit
- PM2.5 Sensor: PMS5003 connected to Serial1 (pins 26, 25)
- Fan Controller: MAX31790 6-channel PWM fan controller (I2C address 0x23)
- Fans: Connect to MAX31790 channels for PM2.5 generation
- Power Supply: Ensure adequate power for ESP32 and connected fans
- WiFi Network: Access to "ag-diamond_2.4GHz" network
- Install PlatformIO in Visual Studio Code
- Clone this repository
- Install dependencies (automatically handled by PlatformIO):
- ArduinoJson @ ^7.2.0
- PubSubClient @ ^2.8
- NTPClient @ ^3.2.1
- Upload the code to ESP32
The system is pre-configured with:
- WiFi Credentials:
ag-diamond_2.4GHznetwork - Target Values: World standard PM2.5 levels {5, 10, 25, 35, 50}
- API Integration: AirGradient API for external sensor data
- Automatic Start: 60-second delay after power-on
- Power On: Connect ESP32 to power source
- Automatic Start: System automatically begins after 60 seconds
- Monitor Progress: Use Serial Monitor (115200 baud) to view logs
- Manual Control (optional):
- Send
startcommand to begin immediately - Send
stopcommand to halt operation
- Send
start- Start PM2.5 generation cycle immediatelystop- Stop the system and turn off fans
- ArduinoJson @ ^7.2.0: JSON parsing for API communication
- PubSubClient @ ^2.8: MQTT communication support
- NTPClient @ ^3.2.1: Network time synchronization
- ESP32 BLE Arduino: Bluetooth Low Energy support (currently disabled)
- HTTPClient: For REST API communication with AirGradient servers
- WiFi Library: Network connectivity management
- Wire Library: I2C communication with MAX31790 fan controller
- Board: uPesy ESP32 Wrover DevKit
- Framework: Arduino for ESP32
- RAM Usage: ~16.6% (54KB/327KB)
- Flash Usage: ~91.1% (1.19MB/1.31MB)
- WiFi: 802.11 b/g/n connectivity
- HTTP/HTTPS: RESTful API communication
- I2C: MAX31790 fan controller communication
- UART: PMS5003 sensor communication
- Auto Start Delay: 60 seconds after boot
- Cycle Duration: 5 hours (1 hour per target level)
- PMS Read Interval: 1 second
- HTTP POST Interval: 60 seconds
- Fan Control Update: 100ms
- ✅ ESP-NOW Removal: Completely removed ESP-NOW wireless protocol
- ✅ WiFi Stability: Fixed connection initialization and runtime errors
- ✅ World Standards: Implemented WHO PM2.5 guideline values
- ✅ Auto Operation: 60-second auto-start with 5-hour cycle
- ✅ Error Handling: Improved HTTP error handling and connection stability
- Cycle Auto-Restart: Add option to automatically restart cycles with configurable break periods
- Web Interface: Develop a web-based control panel for remote monitoring and control
- Data Logging: Implement local data storage and historical trend analysis
- Multi-Sensor Support: Add support for CO2, temperature, and humidity sensors
- Machine Learning: Predictive control algorithms for improved PM2.5 regulation
- Mobile App: Smartphone application for system monitoring and control
- Alert System: Email/SMS notifications for system status and maintenance
- WiFi Connection Failed: Check network credentials and signal strength
- Sensor Not Reading: Verify PMS5003 wiring and power supply
- Fan Not Running: Check MAX31790 I2C connection and power supply
- API Errors: Verify internet connectivity and API token validity
Use Serial Monitor (115200 baud) to view system logs:
[DEBUG]- System status and diagnostics[INFO]- Operational information[ERROR]- Error messages and troubleshooting info
Contributions are welcome! Please feel free to:
- Open issues for bugs or feature requests
- Submit pull requests for improvements
- Share testing results and feedback
- Suggest new features or enhancements
This project is open source. Please check the license file for details.
- v2.0: ESP-NOW removal, WiFi stability improvements, world standard values
- v1.5: Auto-start functionality, target value updates
- v1.0: Initial release with ESP-NOW communication