Projects / Coarse dust and pollen season counter

Coarse dust and pollen season counter

Intermediate2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Test the sensor

    Print continuous readings for a minute.

  2. ESP32

    Add sleep and wake

    Switch the fan off between readings.

  3. ESP32

    Add the clock

    Time-stamp each reading.

  4. ESP32MICROS

    Log to the card

    Write a CSV line.

  5. ESP32

    Run a day

    Check there is one line every 10 minutes.

  6. ESP32

    Mount it outdoors

    Ventilated box, inlet facing down.

  7. ESP32

    Compare

    Check against the city station's readings.

In short

How do you build a coarse dust and pollen season counter?

An SDS011 sensor logs PM10 on a balcony for a year, showing harvest-burning months and dust storms. You need ESP32 DevKit V1, SDS011 particulate matter sensor, MicroSD Card Module, DS3231 RTC module, Resistor 1 kΩ and Resistor 4.7 kΩ. It takes 7 steps and about 120 minutes.

Level
Intermediate
Time
About 120 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
SDS011 5V and GNDESP32 5V (VIN) and GNDPower
SDS011 TXDESP32 GPIO16 (UART2 RX)Sensor data to the ESP32
SDS011 RXDESP32 GPIO17 (UART2 TX)Commands to the sensor (3.3 V logic is fine)
SD module CSESP32 GPIO5Chip select
SD module MOSI, MISO, SCKESP32 GPIO23, GPIO19, GPIO18SPI
SD module VCC and GNDESP32 5V and GNDPower (use a module with a level shifter)
DS3231 SDA and SCLESP32 GPIO21 and GPIO22I2C clock

Code

The SDS011 has a laser and a fan with a limited life, rated at about 8000 hours of continuous running, which is around a year. Waking it for 30 seconds every 10 minutes makes the laser last many years, because it is on about 5 percent of the time; the fan clears the chamber and the reading settles before it is taken. The sketch stores PM2.5 and PM10 with the time in a CSV file on the SD card, which opens directly in a spreadsheet for monthly averages. Mount the sensor in a ventilated, rain-protected box with the inlet facing down and a fine insect mesh, away from kitchen smoke and cooking vents, and keep it out of direct water. Cheap laser sensors read high in humid weather, because water droplets are counted as particles, and they are not reference instruments: use them for trends and compare with the official air quality station for your city. Do not draw health conclusions from them alone. Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module".

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// Dust logger with a duty-cycled SDS011. Libraries: Nova Fitness Sds dust sensors library (SdsDustSensor), RTClib, SD. Board: ESP32 Dev Module.
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <RTClib.h>
#include <SdsDustSensor.h>

SdsDustSensor sds(Serial2);
RTC_DS3231 rtc;
const unsigned long CYCLE_MS = 10UL * 60 * 1000;     // one reading every 10 minutes
const unsigned long WARMUP_MS = 30UL * 1000;         // run the fan for 30 seconds before reading
unsigned long lastCycle = 0;

void setup() {
  Serial.begin(115200);
  sds.begin();                                       // Serial2 is on GPIO16 (RX) and GPIO17 (TX)
  Wire.begin(21, 22); rtc.begin();
  if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  SD.begin(5);
  File f = SD.open("/DUST.CSV", FILE_APPEND);
  if (f && f.size() == 0) f.println("time,pm25,pm10");
  if (f) f.close();
  sds.sleep();
  lastCycle = millis() - CYCLE_MS;                   // take the first reading now
}

void loop() {
  if (millis() - lastCycle >= CYCLE_MS) {
    lastCycle = millis();
    sds.wakeup();
    delay(WARMUP_MS);                                // let the fan clear the chamber
    float p25 = 0, p10 = 0; bool err = true;
    for (int i = 0; i < 10 && err; i++) {
      PmResult pm = sds.queryPm();
      if (pm.isOk()) { p25 = pm.pm25; p10 = pm.pm10; err = false; } else delay(1100);
    }
    sds.sleep();                                     // fan and laser off until the next cycle
    if (!err) {
      DateTime t = rtc.now();
      char line[64]; snprintf(line, sizeof(line), "%04d-%02d-%02d %02d:%02d,%.1f,%.1f", t.year(), t.month(), t.day(), t.hour(), t.minute(), p25, p10);
      File f = SD.open("/DUST.CSV", FILE_APPEND);
      if (f) { f.println(line); f.close(); }
      Serial.println(line);
    }
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Power onFirst line in the file within a minute
Between readingsFan is silent
After a day144 lines
Smoke near the inletPM values jump

If it does not work

No readings

Check TX and RX are crossed and the 5 V supply.

SD errors

Format as FAT32 and check the chip select.

Values very high on humid days

Normal for this sensor; note humidity too.

Fan keeps running

Check the sleep command and library version.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the coarse dust and pollen season counter?

ESP32 DevKit V1, SDS011 particulate matter sensor, MicroSD Card Module, DS3231 RTC module, Resistor 1 kΩ and Resistor 4.7 kΩ.

How long does the coarse dust and pollen season counter take to build?

About 120 minutes for a intermediate maker, in 7 steps.

How do I know the coarse dust and pollen season counter works?

Power on: First line in the file within a minute. Between readings: Fan is silent. After a day: 144 lines.

No readings: what should I check?

Check TX and RX are crossed and the 5 V supply.

SD errors: what should I check?

Format as FAT32 and check the chip select.

Values very high on humid days: what should I check?

Normal for this sensor; note humidity too.

Fan keeps running: what should I check?

Check the sleep command and library version.