Skip to content

Repository files navigation

PM2.5 Room Control System

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.

Overview

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.

Features

  • 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

File Descriptions

  • 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

System Operation

Automatic Cycle

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.

Communication

  • 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

How to Use

Hardware Setup

  • 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

Software Setup

  1. Install PlatformIO in Visual Studio Code
  2. Clone this repository
  3. Install dependencies (automatically handled by PlatformIO):
    • ArduinoJson @ ^7.2.0
    • PubSubClient @ ^2.8
    • NTPClient @ ^3.2.1
  4. Upload the code to ESP32

Configuration

The system is pre-configured with:

  • WiFi Credentials: ag-diamond_2.4GHz network
  • 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

Running the System

  1. Power On: Connect ESP32 to power source
  2. Automatic Start: System automatically begins after 60 seconds
  3. Monitor Progress: Use Serial Monitor (115200 baud) to view logs
  4. Manual Control (optional):
    • Send start command to begin immediately
    • Send stop command to halt operation

Serial Commands

  • start - Start PM2.5 generation cycle immediately
  • stop - Stop the system and turn off fans

Dependencies

  • 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

Technical Specifications

Platform

  • Board: uPesy ESP32 Wrover DevKit
  • Framework: Arduino for ESP32
  • RAM Usage: ~16.6% (54KB/327KB)
  • Flash Usage: ~91.1% (1.19MB/1.31MB)

Communication Protocols

  • WiFi: 802.11 b/g/n connectivity
  • HTTP/HTTPS: RESTful API communication
  • I2C: MAX31790 fan controller communication
  • UART: PMS5003 sensor communication

Timing

  • 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

Recent Updates

  • 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

Future Improvements

  • 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

Troubleshooting

Common Issues

  1. WiFi Connection Failed: Check network credentials and signal strength
  2. Sensor Not Reading: Verify PMS5003 wiring and power supply
  3. Fan Not Running: Check MAX31790 I2C connection and power supply
  4. API Errors: Verify internet connectivity and API token validity

Debug Commands

Use Serial Monitor (115200 baud) to view system logs:

  • [DEBUG] - System status and diagnostics
  • [INFO] - Operational information
  • [ERROR] - Error messages and troubleshooting info

Contributing

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

License

This project is open source. Please check the license file for details.

Version History

  • 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages