Arduino-based Air Quality Monitoring Station: Schematic and Code
Improving air quality is a priority in cities and indoor spaces. With Arduino and a selection of accurate sensors, you can build a reliable monitoring station to measure particulate matter (PM2.5/PM10), temperature, humidity, and pressure. In this article you’ll find everything you need: which components to choose, how to connect them, installation best practices, the wiring diagram, and complete code ready to upload.
What we measure and why
A well-designed hobby station can detect key parameters for a meaningful readout of air quality:
- PM2.5 and PM10: suspended particles that affect respiratory health. A dedicated optical sensor (like the SDS011) is ideal for a reliable estimate.
- Temperature, humidity, and pressure: they influence pollutant dispersion and help correctly interpret particulate data.
These measurements, updated every few seconds and logged over time, allow you to recognize patterns (time of day, weather conditions, space ventilation) and make informed decisions.
Recommended components
For a balance between cost, simplicity, and data quality, here’s a proven configuration:
- Arduino Uno or Nano (5 V compatible).
- SDS011 PM sensor (PM2.5/PM10, 5 V serial interface).
- BME280 environmental sensor (I2C) for temperature, humidity, pressure.
- Dupont wires, breadboard or perfboard, stable 5 V power supply.
- Enclosure with air vents and, optionally, a low-noise fan for a steady airflow.
The SDS011 provides reliable PM readings and communicates over UART at 9600 bps; the BME280 uses I2C, which is easy to wire on Arduino. This combination covers the essential parameters for a complete monitor.
Wiring diagram
The wiring is straightforward: the particulate sensor communicates over serial (SoftwareSerial) and the BME280 over I2C. Remember: the BME280 must be powered at 3.3 V, while the SDS011 requires 5 V. With Arduino Uno/Nano you can connect as follows:
Power: - Arduino 5V -> SDS011 VCC - Arduino GND -> SDS011 GND - Arduino 3.3V -> BME280 VCC - Arduino GND -> BME280 GND I2C (BME280): - Arduino A4 (SDA) -> BME280 SDA - Arduino A5 (SCL) -> BME280 SCL Serial (SDS011) with SoftwareSerial: - Arduino D10 (RX) SDS011 RX (optional; you can leave it unconnected if you don't send commands) - Note: the SDS011 runs at 5 V, compatible with Arduino. Keep the wires short. Overview (simplified): [Arduino UNO] |--5V----> [SDS011 VCC] |--GND---> [SDS011 GND] |--D10 [SDS011 RX] (opt.) |--3.3V-> [BME280 VCC] |--GND--> [BME280 GND] |--A4----> [BME280 SDA] |--A5----> [BME280 SCL]
Complete Arduino code
The following sketch reads PM2.5/PM10 from the SDS011 and temperature/humidity/pressure from the BME280, applies light smoothing, and prints a JSON over serial every 5 seconds.
// Air quality station: SDS011 (PM) + BME280 (T/H/P)
// Required libraries: Adafruit BME280 Library, Adafruit Unified Sensor
// Install via the Arduino IDE Library Manager
#include
#include
#include
#include
#define SDS_RX_PIN 10 // Arduino RX (connected to SDS011 TX)
#define SDS_TX_PIN 11 // Arduino TX (connected to SDS011 RX - optional)
SoftwareSerial sds(SDS_RX_PIN, SDS_TX_PIN);
Adafruit_BME280 bme; // I2C
const float ALPHA = 0.3; // exponential smoothing
float pm25 = NAN, pm10 = NAN;
float pm25_ema = NAN, pm10_ema = NAN;
unsigned long lastPrint = 0;
const unsigned long PRINT_INTERVAL = 5000;
uint8_t frame[10];
uint8_t idx = 0;
bool readSDS011Frame(float &outPM25, float &outPM10) {
while (sds.available()) {
uint8_t b = (uint8_t)sds.read();
switch (idx) {
case 0: if (b == 0xAA) frame[idx++] = b; break;
case 1: if (b == 0xC0) frame[idx++] = b; else idx = 0; break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
frame[idx++] = b;
break;
case 9:
// tail byte
if (b == 0xAB) {
uint16_t sum = 0;
for (int i = 2; i <= 7; i++) sum += frame[i];
uint8_t checksum = sum
if (checksum == frame[8]) {
uint16_t pm25raw = (uint16_t)frame[2] | ((uint16_t)frame[3] << 8);
uint16_t pm10raw = (uint16_t)frame[4] | ((uint16_t)frame[5] <= PRINT_INTERVAL) {
lastPrint = now;
// If EMA not available, use the instantaneous value
float pm25out = isnan(pm25_ema) ? pm25 : pm25_ema;
float pm10out = isnan(pm10_ema) ? pm10 : pm10_ema;
Serial.print("{"pm25":");
Serial.print(isnan(pm25out) ? -1 : pm25out, 1);
Serial.print(","pm10":");
Serial.print(isnan(pm10out) ? -1 : pm10out, 1);
Serial.print(","temp":");
Serial.print(isnan(T) ? -1000 : T, 2);
Serial.print(","humid":");
Serial.print(isnan(H) ? -1 : H, 1);
Serial.print(","press":");
Serial.print(isnan(P) ? -1 : P, 1);
Serial.print(","unit":{"pm":"ugm3","temp":"C","humid":"
Serial.println("}");
}
}
How the code works
The SDS011 continuously sends 10-byte frames at 9600 bps: the parser looks for the start sequence 0xAA 0xC0, verifies the checksum, and if valid, extracts PM2.5 and PM10 values in µg/m³. An exponential filter (EMA) smooths short-term spikes without delaying the response too much. The BME280 provides environmental parameters via I2C. Every 5 seconds the sketch prints a JSON object to serial, easily integrated into local dashboards or cloud services.
Installation and best practices
Placement
Install the station at least 1.5–2 meters above ground, sheltered from splashes and directly away from concentrated sources (kitchen, candles, printers) that would skew the reading. Outdoors, use a ventilated enclosure protected from direct sunlight.
Airflow
The particulate sensor needs a steady airflow. If air exchange is poor, consider a small low-noise 5 V fan positioned so it doesn’t blow dust directly into the sensor. Coarse filters (mesh screen) can reduce insects without changing the measurement too much.
Power supply and electrical noise
Use a stable and reliable 5 V power supply. Avoid overly long USB cables or noisy hubs; interference and voltage drops can cause unstable readings. Keep sensor cables as separate as possible from power lines.
Calibration and data quality
Low-cost optical sensors like the SDS011 offer good relative estimates, but do not replace certified instruments. To improve quality:
- Compare readings for 24–48 hours with a nearby reference station to derive a correction factor.
- Avoid condensation and abrupt temperature swings: high humidity can cause particulate to be overestimated.
- Apply moderate smoothing and moving averages for visualization, but also keep the raw data for analysis.
Expansions: from local to cloud
Want a dashboard? Add a connectivity module (ESP8266/ESP32 instead of Arduino, or an Ethernet shield) and send JSON via MQTT/HTTP to Home Assistant, InfluxDB + Grafana, or ThingSpeak. You can also save data to microSD for historical analysis. If you use an ESP32, leverage a hardware UART for the PM sensor and I2C for the other sensors, keeping the code almost identical.
Troubleshooting
- No data from SDS011: check that D10 is connected to the sensor’s TX and that ground is common. Verify the 9600 bps speed.
- Null BME280 values: try addresses 0x76 and 0x77. Make sure SDA/SCL are correct (A4/A5 on Uno).
- Abnormal PM spikes: check for condensation, dust buildup at the inlet, or a fan blowing directly on the sensor.
Conclusion
With a few components and a bit of patience you can build a robust and insightful monitoring station. It’s an educational project to understand how pollutants are measured and, at the same time, a practical tool to improve the air quality where you live and work.
Ready to build your station?
Gather the components, download the libraries, and upload the sketch: in a few minutes you’ll see the first data on the serial monitor. If you want a personalized step-by-step guide or want to integrate the station with an online dashboard, contact me and let’s immediately start turning your data into useful insights.

Comments