Projects / Auto-speed DIY air purifier

Auto-speed DIY air purifier

Intermediate2.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANOPMS5003

    Read the PMS5003

    Print PM2.5.

  2. NANOIRLZ44

    Wire the fan driver

    MOSFET and flyback diode.

  3. NANO

    Set up 25 kHz PWM

    Silent fan control.

  4. NANO

    Add the speed map

    40 to 100 percent.

  5. NANO

    Add the hysteresis

    Start at 30, stop at 15.

  6. NANO

    Seal the filter

    No gaps at the edges.

  7. NANO

    Test with incense smoke

    Time how fast PM2.5 falls.

In short

How do you build an auto-speed DIY air purifier?

A PMS5003 reading sets the speed of a 12 V fan pushing air through a HEPA filter, so the purifier runs harder only when the air is dirty. You need Arduino Nano, PMS5003 particulate matter sensor, MOSFET IRLZ44N, Resistor 10 kΩ, Schottky Diode 1N5819, 12 V DC fan 80 mm, 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female) and SSD1306 OLED Display. It takes 7 steps and about 150 minutes.

Level
Intermediate
Time
About 150 min
Parts
9

Parts list

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

Wiring

FromToWhy
PMS5003 TXNano D2Data in
PMS5003 VCC and GNDNano 5V and GNDPower
Nano D9IRLZ44N gate, with 10 kΩ gate to groundFan PWM
12 V adapter plus (through DC jack)Fan plusFan supply
Fan minusIRLZ44N drainSwitched ground
1N5819Across the fan, stripe to plusFlyback protection
IRLZ44N source, adapter minus, Nano GNDJoinedCommon ground
OLED SDA and SCLNano A4 and A5Display

Code

The PMS5003 counts particles with a laser and a fan of its own and sends a 32-byte frame every second; the sketch checks its sum before trusting the PM2.5 number. Below 15 micrograms per cubic metre the purifier stays off, above 30 it switches on, and between 30 and 150 the speed climbs from 40 to 100 percent, so it runs hard only when the air is dirty and stays quiet otherwise. Tape the fan to the back of a HEPA filter sheet with no gaps, because air that leaks round the edges bypasses the filter; use a 12 V fan with a guard, and keep the sensor at the clean side of the room, away from the fan outlet. To test, light an incense stick near a closed room and watch PM2.5 rise and then fall, and measure how fast it drops. This is a hobby purifier; its flow is much smaller than commercial ones, so it suits a small room, and it makes no ozone. Change the filter on schedule. Keep wiring neat, and use a fused 12 V adapter. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).

Runs on a virtual Arduino Nano 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).

// Auto-speed purifier: PM2.5 sets the fan speed with hysteresis and 25 kHz PWM. Libraries: U8g2 (U8x8). Board: Arduino Nano.
#include <SoftwareSerial.h>
#include <U8x8lib.h>
SoftwareSerial pms(2, 3);
U8X8_SSD1306_128X64_NONAME_HW_I2C oled(U8X8_PIN_NONE);
int pm25 = 0;
bool running = false;
void pwmBegin() {                                   // 25 kHz PWM on D9, silent for a fan
  pinMode(9, OUTPUT);
  TCCR1A = _BV(COM1A1) | _BV(WGM11);
  TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10);
  ICR1 = 639;
}
void setFan(int pct) { OCR1A = (long)constrain(pct, 0, 100) * 639 / 100; }
bool readPms() {                                    // 32-byte frame: 0x42 0x4D, PM2.5 (atmospheric) at bytes 12-13
  static uint8_t buf[32]; static int n = 0;
  while (pms.available()) {
    uint8_t b = pms.read();
    if (n == 0 && b != 0x42) continue;
    if (n == 1 && b != 0x4D) { n = 0; continue; }
    buf[n++] = b;
    if (n == 32) {
      n = 0;
      uint16_t sum = 0; for (int i = 0; i < 30; i++) sum += buf[i];
      if (sum == ((uint16_t)buf[30] << 8 | buf[31])) { pm25 = (buf[12] << 8) | buf[13]; return true; }
    }
  }
  return false;
}
void setup() {
  pms.begin(9600);
  oled.begin(); oled.setFont(u8x8_font_chroma48medium8_r);
  pwmBegin(); setFan(0);
}
void loop() {
  if (readPms()) {
    if (!running && pm25 > 30) running = true;      // start above 30
    if (running && pm25 < 15) running = false;      // stop below 15: hysteresis stops chatter
    int speed = 0;
    if (running) speed = map(constrain(pm25, 30, 150), 30, 150, 40, 100);
    setFan(speed);
    char line[17];
    oled.clear();
    snprintf(line, sizeof(line), "PM2.5 %d", pm25); oled.drawString(0, 0, line);
    snprintf(line, sizeof(line), "Fan %d%%", speed); oled.drawString(0, 2, line);
  }
}

Test checklist

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

CheckExpected
Clean airFan off
SmokeFan starts and speeds up
Smoke clearedFan stops below 15
Fan noiseNo whine at low speed

If it does not work

No readings

Check the TX wire to D2 and the 9600 baud rate.

Fan chatters

Widen the 15 to 30 band.

Whine

Check the 25 kHz timer setup.

Readings stay high

Keep the sensor away from the outlet.

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

Ask Lark AI

Common questions

What parts do I need for the auto-speed DIY air purifier?

Arduino Nano, PMS5003 particulate matter sensor, MOSFET IRLZ44N, Resistor 10 kΩ, Schottky Diode 1N5819, 12 V DC fan 80 mm, 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female) and SSD1306 OLED Display.

How long does the auto-speed DIY air purifier take to build?

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

How do I know the auto-speed DIY air purifier works?

Clean air: Fan off. Smoke: Fan starts and speeds up. Smoke cleared: Fan stops below 15.

No readings: what should I check?

Check the TX wire to D2 and the 9600 baud rate.

Fan chatters: what should I check?

Widen the 15 to 30 band.

Whine: what should I check?

Check the 25 kHz timer setup.

Readings stay high: what should I check?

Keep the sensor away from the outlet.