PM2.5 Monitor


Make sure you select correct libraries for PMS7003 and OLED

// Libraries
#include <Wire.h>    // I2C library
#include <ESP8266WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <pms.h>
#include "SSD1306.h"

To use the monitor with the real time from NTP server, provide the Wifi name and password with offset time to correct with your timezone. If not, the wifi setup will be failed anb break out the the loop and only show the concentration of PM2.5.

// Setup for NTP time
#const char* ntpServer = "";
const long utcOffsetInSeconds = 7*3600; // for GMT+7 
//const int   daylightOffset_sec = 0; // apply to US
NTPClient timeClient(ntpUDP, ntpServer, utcOffsetInSeconds);

this snippet shows the after 10 loops, the for loop will break out, and the NTP time request will be forgone.

//code snippet
while (WiFi.status() != WL_CONNECTED) {
    Serial.printf(" %i ", i);
    if (i == 5){
        WiFi.begin(wifi_ssid, wifi_password);
    String tmp = "Connecting..." + String(i);
    if (i >=10){
        break;  // break out the while loop
// If you want to keep search for internet (given you really have one)
// uncomment two lines below. The loop will continue until wifi is connected.
//      ESP.restart();
//      Serial.println("Resetting ESP");

The last part to customize is the interval to update the readings. By default in this code, the reading is updated for every 10 seconds. Change the interval by INVL variable. Now the loop will excecute forever.

//This loop run forever
void loop() {
    uptime = round(millis()/1000L);
    if ((uptime -lastSampling) > INVL){

Check the GitHub repo for the full sketch, wiring diagram and the setup. Use a Arduino IDE, open the sketch with installed libraries, select to correct board and hopefully, it will turn out expected. If you would like what else can be done with this base model. Let move on the page 4.