Why Nodemcu v2 Esp8266 unable to read measurement from SDS011 Nova PM sensors?

Currently i'm trying to use my nodemcu esp8266 v2 read PM10 and PM2.5 measurements from SDS011 Nova PM Sensor. When I use the example sketch from SDS011 Library, I unable to obtain any measurement from the sensor. All the wiring connection is correct and the led behind sds011 blinking checked, fan is turning checked, esp8266 is working checked but Why still unable to read measurement from Nova Pm sensors? I also attached the code below. Can anyone help me out please ???



Screenshot 2024-01-27 163755

#include <SdsDustSensor.h>
#include <SoftwareSerial.h>

// SDS011 software serial pins
#define SDS_RX D2
#define SDS_TX D1
SoftwareSerial sds(SDS_RX, SDS_TX);

void setup() {
  // Initialize Serial communication with the computer
  Serial.begin(115200);
  delay(100);  // Short delay after initializing Serial
  Serial.println("Initializing SDS011 Air Quality Monitor...");

  // Initialize SoftwareSerial communication with SDS011
  sds.begin(9600);
}

void loop() {
  // Look for the starting byte of the SDS011 data frame
  while (sds.available() && sds.read() != 0xAA) { }

  if (sds.available()) {
    Serial.println("Data available from SDS011...");
  }

  // Once we have the starting byte, attempt to read the next 9 bytes
  byte buffer[10];
  buffer[0] = 0xAA;  // The starting byte we already found
  if (sds.available() >= 9) {
    sds.readBytes(&buffer[1], 9);

    // Check if the last byte is the correct ending byte
    if (buffer[9] == 0xAB) {
      int pm25int = (buffer[3] << 8) | buffer[2];
      int pm10int = (buffer[5] << 8) | buffer[4];
      float pm2_5 = pm25int / 10.0;
      float pm10 = pm10int / 10.0;

      // Print the values
      Serial.print("PM2.5: ");
      Serial.print(pm2_5, 2);  // 2 decimal places
      Serial.print(" µg/m³   ");
      Serial.print("PM10: ");
      Serial.print(pm10, 2);  // 2 decimal places
      Serial.println(" µg/m³   ");
    } else {
      Serial.println("Invalid ending byte from SDS011.");
    }
  } else {
    Serial.println("Not enough data from SDS011.");
  }
  delay(1000);  // Delay before the next read to avoid flooding the serial
}

your sensor is rated for 5V and needs 70mA - are you providing that ?

your ESP8266 is 3.3V - are you compliant with the data coming back from the module's Tx?

Should be because I connecting the 5v pin from PM sensor to NodeMCU esp8266 Vin pin. I also tested by using arduino uno connect 5v to 5v pin but at the end still cannot get the measurement reading.

Does this Vin pin actually deliver 5V straight of the USB ? I don't think this board has a 5V regulator (it has a 3.3V one) and there is likely at least a diode on that path that will drop the USB voltage to 4.2 or 4.3V may be ? is that enough for the sensor?

does the module answer with 5V on its Tx (which would go the the ESP Rx pin which can only accept 3.3V)

with which code? On a UNO you would not use pin 1 and 2

hmm.....quite make sense but I haven't check that with multimeter.

I used the code attached below, I also tried changed the Tx pin to D4 and Rx pin to D3, 5V to 5V pin and still unable to get the measurement reading using Arduino Uno. By the way, I also attached the feedback from Serial Monitor. Any idea what mistake i made? and Thx for reply to my problem.

#include <SDS011.h>
#include <SPI.h>

float p10, p25;
int error;
SDS011 nova;

void setup() {
  nova.begin(3, 4);
  Serial.begin(9600);
}

void loop() {
  error = nova.read(&p25, &p10);

  if (!error) {
    Serial.print("PM2.5: ");
    Serial.println(p25);
    Serial.print("PM10: ");
    Serial.println(p10);
  } else {
    Serial.println("Error reading data from SDS011");
  }

  delay(2000);
}


Wait.... I managed to get PM measurement readings using Arduino Uno using the following code, I think I made mistake on tx and rx pin during arduino uno and sds011 wiring connection.

#include "SdsDustSensor.h"
 
int rxPin = 0;
int txPin = 1;
SdsDustSensor sds(rxPin, txPin);
 
void setup() {
  Serial.begin(9600);
  sds.begin();
 
  Serial.println(sds.queryFirmwareVersion().toString()); // prints firmware version
  Serial.println(sds.setActiveReportingMode().toString()); // ensures sensor is in 'active' reporting mode
  Serial.println(sds.setContinuousWorkingPeriod().toString()); // ensures sensor has continuous working period - default but not recommended
}
 
void loop() {
  PmResult pm = sds.readPm();
  if (pm.isOk()) {
    Serial.print("PM2.5 = ");
    Serial.print(pm.pm25);
    Serial.print(", PM10 = ");
    Serial.println(pm.pm10);
 
    // if you want to just print the measured values, you can use toString() method as well
    Serial.println(pm.toString());
  } else {
    // notice that loop delay is set to 0.5s and some reads are not available
    Serial.print("Could not read values from sensor, reason: ");
    Serial.println(pm.statusToString());
  }
 
  delay(500);
}

Now, last problem is how to get the measurement reading using esp8266 v2 ? Should I replace with different model with 5V supply and what pin number should I connect then? because currently I'm doing an indoor air quality controller which require WIFI connection between device to device.

You probably need a quality 5V supply and a voltage adapter for the serial line

In the code of post #1 you try to read the sensor directly with a NodeMCU (and that Serial code doesn't feel right to me), while in later posts where you report success with an Arduino Uno you use the sds.readPm() call to get the data. Why that difference? The Uno code should run on the ESP just fine - only changes needed really are the Serial pins.

Or is it possible for me to use a bi-directional logic level shifter which connect the LV pin to 3.3v nodemcu and HV pin to my 5V pin Nova PM sensors for stepping up voltage from 3.3v to 5v ?

Because i use the example sketch from sds011 library and I thought different arduino device have different code. I know that is my mistake and I'm new to this :slight_smile: Btw thanks for pointing out.

if the Vin pin of your NodeMCU does not deliver 5V then it might be an issue - the sensor requires 5V so you need to bring that in . May be it works with a bit less, may be not.

Then indeed a bi-directional logic level shifter between then 5V of the sensor and the 3.3V expected by the NodeMCU (at least for its software Rx pin) is needed. You could achieve the same with a couple of resistor set as a voltage divider.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.