Contenuti

PMS5003 Sensor Library for Esp32 idf

Plantower PMS5003 is a laser dust sensor. It can sense particulates of various sizes (PM1, PM2.5, PM10) from sources like smoke, dust, pollen, metal and organic particles.

This library can be used with multiple sensors at the same time. For each sensor you can choose between one shot or periodic data read.

The source code is available on my GitHub at the following link.

Working principle

This sensor uses laser scattering to radiate suspending particles in the air, then collects scattering light to obtain the curve of scattering light change with time. The microprocessor calculates equivalent particle diameter and the number of particles with different diameter per unit volume.

About the Library

To initialize the library you need to setup the pmsx003_config_t structure as below sample

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
static void pms_callback(pm_data_t *sensor_data) {
    ESP_LOGI(TAG, "pm10: %d ug/m3", sensor_data->pm10);
    ESP_LOGI(TAG, "pm2.5: %d ug/m3", sensor_data->pm2_5);
    ESP_LOGI(TAG, "pm1.0: %d ug/m3", sensor_data->pm1_0);
    ESP_LOGI(TAG, "particles > 0.3um / 0.1L: %d", sensor_data->particles_03um);
    ESP_LOGI(TAG, "particles > 0.5um / 0.1L: %d", sensor_data->particles_05um);
    ESP_LOGI(TAG, "particles > 1.0um / 0.1L: %d", sensor_data->particles_10um);
    ESP_LOGI(TAG, "particles > 2.5um / 0.1L: %d", sensor_data->particles_25um);
    ESP_LOGI(TAG, "particles > 5.0um / 0.1L: %d", sensor_data->particles_50um);
    ESP_LOGI(TAG, "particles > 10.0um / 0.1L: %d", sensor_data->particles_100um);
}


pmsx003_config_t pms_conf = {
    .sensor_id = 1, // logic ID for your device
    .uart_port = UART_NUM_2,
    .indoor = false,
    .enabled = true,
    .periodic = true,
    .periodic_sec_interval = 300, // every five minutes, min value is 30s
    .callback = &pms_callback,
    .set_pin = CONFIG_SET_GPIO,
    .reset_pin = CONFIG_RESET_GPIO,
    .uart_tx_pin = CONFIG_TX_GPIO,
    .uart_rx_pin = CONFIG_RX_GPIO,
};

void app_main(void) {
    idf_pmsx5003_init(&pms_conf);
}

Note

You can configure the library to execute a periodic data read. Between each data sample the sensor will be disabled; datasheet suggests to wait at least 30s after sensor wake up. For this reason periodic_sec_interval parameter min value is 30.

Datasheet

Sensor datasheet can be downloaded here