Forked library with the following changes:
- readings of raw particle counts added (Particle sizes 0.3, 0.5, 1.0, 2.5, 5.0, 1.0)
- support for ST-variant sensors (Formaldehyde (HCHO), temperature & humidity)
Tested on Arduino Nano using PMS 7003 and Arduino MKR1000 using PMS 5003ST
Arduino library for Plantower PMS sensors. Supports PMS x003 sensors (1003, 3003, 5003, 6003, 7003). Supports PMS 5003ST sensor (likely other PMSxxxxST models, but untested).
Just use Arduino Library Manager and search "Plantower PMS Library" in Sensors category.
- easy as possible,
- minimal memory consumption,
- non-blocking functions,
- supporting a wide range of PMS sensors from Plantower,
- supporting additional modes e.g.: sleeping, passive, active (depends on the sensor model).
As a data source you can use any object that implements the Stream class, such as Wire, Serial, EthernetClient, e.t.c.
Read in active mode.
Default mode is active after power up. In this mode sensor would send serial data to the host automatically. The active mode is divided into two sub-modes: stable mode and fast mode. If the concentration change is small the sensor would run at stable mode with the real interval of 2.3s. And if the change is big the sensor would be changed to fast mode automatically with the interval of 200~800ms, the higher of the concentration, the shorter of the interval.
#include "PMS.h"
PMS pms(Serial);
PMS::DATA data;
void setup()
{
Serial.begin(9600); // GPIO1, GPIO3 (TX/RX pin on ESP-12E Development Board)
Serial1.begin(9600); // GPIO2 (D4 pin on ESP-12E Development Board)
}
void loop()
{
if (pms.read(data))
{
Serial1.print("PM 1.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_1_0);
Serial1.print("PM 2.5 (ug/m3): ");
Serial1.println(data.PM_AE_UG_2_5);
Serial1.print("PM 10.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_10_0);
Serial1.println();
}
// Do other stuff...
}
PM 1.0 (ug/m3): 13
PM 2.5 (ug/m3): 18
PM 10.0 (ug/m3): 23
PM 1.0 (ug/m3): 12
PM 2.5 (ug/m3): 19
PM 10.0 (ug/m3): 24
...
Read in passive mode but not the best way (see additional remarks).
#include "PMS.h"
PMS pms(Serial);
PMS::DATA data;
void setup()
{
Serial.begin(9600); // GPIO1, GPIO3 (TX/RX pin on ESP-12E Development Board)
Serial1.begin(9600); // GPIO2 (D4 pin on ESP-12E Development Board)
pms.passiveMode(); // Switch to passive mode
}
void loop()
{
Serial1.println("Waking up, wait 30 seconds for stable readings...");
pms.wakeUp();
delay(30000);
Serial1.println("Send read request...");
pms.requestRead();
Serial1.println("Reading data...");
if (pms.readUntil(data))
{
Serial1.print("PM 1.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_1_0);
Serial1.print("PM 2.5 (ug/m3): ");
Serial1.println(data.PM_AE_UG_2_5);
Serial1.print("PM 10.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_10_0);
}
else
{
Serial1.println("No data.");
}
Serial1.println("Going to sleep for 60 seconds.");
// when using SoftwareSerial for communication with PMS flush HW serial channel first before switchin to SoftwareSerial,
// (sensor might not be put to sleep mode properly and fan keeps running)
// Serial1.flush();
pms.sleep();
delay(60000);
}
Waking up, wait 30 seconds for stable readings...
Send read request...
Reading data...
PM 1.0 (ug/m3): 13
PM 2.5 (ug/m3): 18
PM 10.0 (ug/m3): 23
Going to sleep for 60 seconds.
Waking up, wait 30 seconds for stable readings...
Send read request...
Reading data...
PM 1.0 (ug/m3): 12
PM 2.5 (ug/m3): 19
PM 10.0 (ug/m3): 24
Going to sleep for 60 seconds.
...
Retrieve Formaldehyde (HCHO), Temperature and Humidity. These sensors are all internal to the unit and thus are monitoring conditions from the airflow and may therefore differ from other "ambient" sensor readings.
#include "PMS.h"
PMS pms(Serial);
PMS::DATA data;
void setup()
{
Serial.begin(9600); // GPIO1, GPIO3 (TX/RX pin on ESP-12E Development Board)
Serial1.begin(9600); // GPIO2 (D4 pin on ESP-12E Development Board)
}
void loop()
{
if (pms.read(data))
{
// Works for PMS xxxxST variant sensors only!
Serial1.print("Formaldehyde (mg/m3): ");
Serial1.println(data.AMB_HCHO);
Serial1.print("Airflow Temperature (C): ");
Serial1.println(data.AMB_TMP);
Serial1.print("Airflow Humidity (%H): ");
Serial1.println(data.AMB_HUM);
Serial1.println();
}
// Do other stuff...
}
Formaldehyde (mg/m3): 0
Airflow Temperature (C): 21.32
Airflow Humidity (%H): 49.67
Formaldehyde (HCHO): 2
Airflow Temperature (C): 21.38
Airflow Humidity (%H): 49.66
...
Tested with PMS 7003 and ESP-12E Development Board. All Plantower PMS sensors use the same protocol
Please consider, that delay() function in examples is a blocking function.
Try to avoid such a solution if your project requires it (see Expert.ino example in examples directory).
For more accurate measurements, you can read several samples (in passive or active mode) and calculate the average.
Stable data should be got at least 30 seconds after the sensor wakeup from the sleep mode because of the fan's initial startup disturbing settled dust.