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.
OLED reads:
PM2.5 0.00
PM10 0.00
Sourav Gupta
PermalinkPlease debug using the serial port. Check the variable values on each steps.
- Log in or register to post comments
Joined February 12, 2018 696Monday at 02:11 PM