SDS011 PM sensor not updating

HI,

this is my first project, and first go at coding, i followed the tutorial Air Quality Analyzer using Arduino and Nova PM Sensor SDS011 to Measure PM2.5 and PM10

but then learned i have a different OLED to the tutorial, mine is connected to I2c.

so basically, i confirmed my sensor works on my pc, and the Arduino nano works. it shows the text, but the it reads zero. im sure it will be a simple fix for you guys, but ive tried to figure it out and its taken me 2 days.

here is the code:

#include <SDS011.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
float p10,p25;
int error;
SDS011 my_sds;
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define I2C_SDA  4
#define I2C_SCL  5
#define SDS011 my_sds;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

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

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
    
}
void loop() {
      error; my_sds.read(&p25,&p10);
  if (! error) {
    Serial.println("P2.5: "+String(p25));
    Serial.println("P10:  "+String(p10));
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,15);
display.println("PM2.5");
display.setCursor(67,15);
display.println(p25);
display.setCursor(0,40);
display.println("PM10");
display.setCursor(67,40);
display.println(p10);
display.display();
display.clearDisplay();
}
delay(1000);
}

the serial monitor, does update, and i can see activity on the Arduino, the sensor is powered, fan operates. also the circuit is connected same as the tutorial, except the modification to the OLED.

Try commenting the clearDisplay out. It will likely make a mess on the OLED as values change, but it may allow you to confirm that the display is working.

tried that, it does indeed make a mess, but no movement on the screen, shows the Adafruit logo over the PM2.5.

I expect clearing the display in setup will get rid of the logo.

yep, done that, cleared the logo, but no movement,

oled display looks like this:

PM2.5 0.00
PM10 0.00

And yet, the serial monitor shows non-zero values?

I wonder if the display library can't handle float. What if you try printing a literal int e.g. 123.

Im not sure how to print int, can you reply something i can just copy in place? please

Your serial output shows the same thing - zeroes. I suspect then that the issue is nothing to do with the display.

What code were you using to test the sensor when you believed it was working?

dust sensor viewer, with a USB adaptor direct to pc. when its connected to my pc with correct drivers etc, it works a treat. give the sensor some smoke... numbers jumps up and so on. then plugged it back into the bread board, ran my code. still the same.
i used another code that has moving text, and that worked fine.

im not sure if my code has the uses the correct tx/rx pins,

void setup() {

my_sds.begin(3,4);

Can you post the code (and serial output) that was giving non-zero readings?

no, it was a application that i downloaded and ran, so im not sure where to get the code for that.

Your code looks similar to the library example, so all I can think of is that you have a wiring issue. How is it wired up?

so ive wired the sensor to the nano the same as the example,
OLED is:
vcc-5v
GND-GND
SCL-A5
SDA-A4.

SENSOR:
5V-5V
GND-GND
RXD-D3
TXD-D4

I suspect that you have RX and TX reversed.

that worked,
i tried that before but it didnt work, but now its fixed. thanks for your help.

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