Table of Contents

Plantower PMS5003 particulate-matter sensor

The PMS5003 measures PM1.0, PM2.5, and PM10 mass concentration and particle counts in six size bins. This binding reads the sensor's 32-byte active-reporting frames over UART and validates the frame header, length, and checksum.

Documentation

ESP32-C3 Super Mini wiring

PMS5003 ESP32-C3 Super Mini Notes
Pin 1 VCC 5V Sensor power
Pin 2 GND GND Common ground
Pin 4 RXD GPIO21 (TX) Optional for active-reporting mode
Pin 5 TXD GPIO20 (RX) Sensor data to ESP32 COM2 RX
Pin 3 SET GPIO3 Driven high for normal operation
Pin 6 RESET GPIO2 Driven high to keep the sensor out of reset

The PMS5003 UART uses 9600 baud, 8 data bits, no parity, and one stop bit. Configure the ESP32 UART pin functions before opening SerialPort. After reset, allow 30 seconds for the fan and measurement chamber to stabilize before reading the first frame.

Usage

const int Reset = 2;
const int Set = 3;

GpioController gpioController = new GpioController();
GpioPin resetPin = gpioController.OpenPin(Reset, PinMode.Output);
GpioPin setPin = gpioController.OpenPin(Set, PinMode.Output);
setPin.Write(PinValue.High);
resetPin.Write(PinValue.Low);
Thread.Sleep(100);
resetPin.Write(PinValue.High);
Thread.Sleep(30000); // Allow the fan and measurement chamber to stabilize.
Configuration.SetPinFunction(Gpio.IO20, DeviceFunction.COM2_RX);
Configuration.SetPinFunction(Gpio.IO21, DeviceFunction.COM2_TX);

SerialPort serialPort = new SerialPort("COM2", Pms5003.DefaultBaudRate, Parity.None, 8, StopBits.One);
serialPort.ReadTimeout = 5000;
serialPort.Open();
Pms5003 sensor = new Pms5003(serialPort);

PmsReading reading = sensor.Read();
Debug.WriteLine($"PM2.5: {reading.Pm2Point5Atmospheric} ug/m3");

Read() synchronizes to the next frame header. A serial timeout is surfaced by SerialPort; malformed frames throw InvalidOperationException. Dispose the sensor to dispose its serial port, or pass shouldDispose: false to retain ownership.