An ESP8266-based smart air quality monitoring system that measures temperature, humidity, and CO2 levels, displays the data on RGB LED matrices, and publishes to Home Assistant via MQTT.
- Temperature & Humidity Monitoring: Using AM2302 DHT22 sensor
- CO2 Measurement: Using Sensirion SCD40 sensor (ppm)
- Visual Display: 3x 8x8 RGB LED matrices (NeoPixel) for real-time data visualization
- Home Assistant Integration: MQTT protocol for seamless integration
- Low Power: USB-C powered (5V)
- WiFi Connectivity: ESP8266 microcontroller
- Microcontroller: ESP8266 (NodeMCU, Wemos D1 Mini, or similar Wi-Fi capable MCUs)
- Temperature/Humidity Sensor: AM2302 DHT22
- CO2 Sensor: Sensirion SCD40
- Display: 4 pcs WS2812B 8x8 RGB LED matrices
- Power: USB-C connector with 5V power supply
DHT22 Data Pin -> GPIO2 (D4 on NodeMCU)
SCD40 SDA -> GPIO4 (D2 on NodeMCU)
SCD40 SCL -> GPIO5 (D1 on NodeMCU)
LED Matrix Data -> GPIO14 (D5 on NodeMCU)
VCC -> 3.3V or 5V voltage source
GND -> GND
DATA -> GPIO2 (with 10kΩ pull-up resistor to VCC)
VDD -> 3.3V voltage source
GND -> GND
SDA -> GPIO4
SCL -> GPIO5
VCC -> 5V
GND -> GND
DIN -> GPIO14
Note: Chain the three 8x8 matrices together by connecting DOUT of one matrix to DIN of the next.
- DHT sensor library (Adafruit)
- Adafruit Unified Sensor
- SparkFun SCD4x Arduino Library
- Adafruit NeoPixel
- Adafruit NeoMatrix
- Adafruit GFX Library
- PubSubClient (MQTT)
-
Clone the repository:
git clone https://github.com/mikoa001/smart-air-sensor.git cd smart-air-sensor -
Configure your settings:
cp src/config.h.example src/config.h
-
Edit
src/config.hwith your WiFi and MQTT credentials:#define WIFI_SSID "your_wifi_ssid" #define WIFI_PASSWORD "your_wifi_password" #define MQTT_SERVER "192.168.1.100" #define MQTT_USER "mqtt_user" #define MQTT_PASSWORD "mqtt_password"
-
Build and upload:
pio run --target upload
-
Monitor serial output:
pio device monitor
-
Install ESP8266 board support:
- File → Preferences → Additional Board Manager URLs
- Add:
http://arduino.esp8266.com/stable/package_esp8266com_index.json - Tools → Board → Board Manager → Search "ESP8266 Boards" and install
-
Install required libraries:
- Sketch → Include Library → Manage Libraries
- Install all libraries listed in the Software Requirements section
-
Open the project:
- Rename
src/main.cpptosmart-air-sensor.ino - Open in Arduino IDE
- Rename
-
Configure settings as described above
-
Select your board:
- Tools → Board → ESP8266 Boards → Generic ESP8266 Module
-
Upload the sketch
The sensor publishes to the following MQTT topics (configurable in config.h):
home/sensor/temperature- Temperature in Celsiushome/sensor/humidity- Relative humidity in percentagehome/sensor/co2- CO2 concentration in ppmhome/sensor/status- Sensor online status
Default intervals (configurable in config.h):
- Sensor reading & MQTT publish: 30 seconds
- Display rotation: 2 seconds (cycles through temp, humidity, CO2)
The display cycles through three modes:
- Temperature: Orange color
- Humidity: Blue color
- CO2 Level:
- Green: < 1000 ppm (Good)
- Yellow: 1000-2000 ppm (Warning)
- Red: > 2000 ppm (Poor)
Add the following to your Home Assistant configuration.yaml:
mqtt:
sensor:
- name: "Air Quality Temperature"
state_topic: "home/sensor/temperature"
unit_of_measurement: "°C"
device_class: temperature
- name: "Air Quality Humidity"
state_topic: "home/sensor/humidity"
unit_of_measurement: "%"
device_class: humidity
- name: "Air Quality CO2"
state_topic: "home/sensor/co2"
unit_of_measurement: "ppm"
icon: mdi:molecule-co2Restart Home Assistant after adding the configuration.
Example output:
Smart Air Quality Sensor Starting...
LED Matrix initialized
DHT22 initialized
I2C initialized
SCD40 initialized
Connecting to WiFi...
WiFi connected
IP address: 192.168.1.50
Attempting MQTT connection...connected
Temperature: 22.5°C, Humidity: 45.2%
CO2: 678 ppm
Published temperature: 22.5
Published humidity: 45.2
Published CO2: 678
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request and I will reveiw it within 1-2 weeks.