Hello Forum,
I want to read the PWM output signals on the SDS011. Seems that this feature is rarely used. It is described here on page https://cdn-reichelt.de/documents/datenblatt/X200/SDS011-DATASHEET.pdf Page 5 to 7
It seems that I have to read in a specific timerange, but I don´t know jow to do this the right way.
I just tried reading PWM:
int pin = 14; // Check what pin to use
int pwm_25; // Duration of the pulse
// setup serial and input, output pins
void setup()
{
Serial.begin(9600);
pinMode(pin, INPUT);
}
void loop()
{
pwm_25 = pulseIn(pin, HIGH);
Serial.println(pwm_25);
delay(100);
}
which gave me values like this:
244619
257523
260496
264497
265494
265485
266497
266470
267488
267469
267501
268486
268482
268475
268491
268477
268474
268493
268464
268471
265490
230692
198865
174007
147170
120318
94467
78552
57673
47727
36790
27842
24860
20883
18891
18892
Okay, if someone have the same Problem, here is the answer:
#define pm25Pin 12
#define pm10Pin 13
void setup() {
pinMode(pm25Pin, INPUT);
pinMode(pm10Pin, INPUT);
Serial.begin(9600);
}
void loop() {
Serial.print("PM2.5 = ");
Serial.println(pulseIn(pm25Pin, HIGH, 1500000) / 1000 - 2);
Serial.print("PM10 = ");
Serial.println(pulseIn(pm10Pin, HIGH, 1500000) / 1000 - 2);
}
nullsports:
Okay, if someone have the same Problem, here is the answer:
#define pm25Pin 12
#define pm10Pin 13
void setup() {
pinMode(pm25Pin, INPUT);
pinMode(pm10Pin, INPUT);
Serial.begin(9600);
}
void loop() {
Serial.print("PM2.5 = ");
Serial.println(pulseIn(pm25Pin, HIGH, 1500000) / 1000 - 2);
Serial.print("PM10 = ");
Serial.println(pulseIn(pm10Pin, HIGH, 1500000) / 1000 - 2);
}
It is an excellent solution, only there is a point where if you expose dust a lot the PM10 goes a little crazy. Since it marks exaggerated values without meaning, I would like to find a way to solve this.
Hi everyone,
I made some comparisons between serial and PWM output from an SDS011 sensor. I found different numbers. I found PWM concentrations about 10 times less than Serial output, both for 10 and 2.5.
Did anyone find the same thing?
I used an Arduino UNO for both outputs. My code follows:
#define SSRxPin 4
#define SSTxPin 3
#define PIN10 6
#define PIN25 5
#define PAYLOAD_LEN 8
#include <SoftwareSerial.h> // comunicazione con Feather
SoftwareSerial mySerial(SSRxPin, SSTxPin); //RX, TX verso ARduino
byte received[PAYLOAD_LEN];
byte i = 0;
byte ch = ' ';
byte flag = 0;
float PM10 = 0;
float PM25 = 0;
float TimePassed = 0;
float TimeOld = 0;
float Periodo = 10000;
void setup() {
pinMode(SSTxPin, OUTPUT);
pinMode(SSRxPin, INPUT);
while(!mySerial);
mySerial.begin(9600);
delay(1000);
while(!Serial);
Serial.begin(115200); // non minore di questa altrimenti si disincronizza
delay(1000);
Serial.println(" ProvaSDS011_Serial_PWM.ino");
}
void loop() {
if(mySerial.available() > 0){
ch = mySerial.read();
Serial.print(ch,HEX);Serial.print(" ");
if(flag){
received[i] = ch;
i++;
}
if(ch == 0xAA && !flag){
flag = 1;
i = 0;
}
if(ch == 0xAB && flag){
flag = 0;
Serial.println();
for(i = 0;i < PAYLOAD_LEN; i++){
Serial.print(received[i]);Serial.print(" ");
}
Serial.println();
int check = received[1]+received[2]+received[3]+received[4]+received[5]+received[6];
check = check % 256;
if(check != received[7]){
Serial.println(" ERRORE ");
}
Serial.print(" check ");Serial.println(check);
PM25 = float(received[2])*256.0 + float(received[1])/10.0;
PM10 = float(received[4])*256.0 + float(received[3])/10.0;
Serial.print(" PM10 ");Serial.print(PM10,1); Serial.print(" PM25 ");Serial.println(PM25,1);
}
}
TimePassed = millis()-TimeOld;
if(TimePassed > Periodo){
unsigned long durata1 = pulseIn(PIN10,HIGH,150000000);
// delay(5000);
unsigned long durata2 = pulseIn(PIN25,HIGH,150000000);
float Conc10 = float(durata1)/1000.0 - 2; //Conc in ug/m3
float Conc25 = float(durata2)/1000.0 - 2; //Conc in ug/m3
if(Conc10 < 0)Conc10 = 0;
if(Conc25 < 0)Conc25 = 0;
Serial.print(" ");Serial.print(durata1);Serial.print(" Conc10 ");
Serial.print(Conc10,1);Serial.print(" ");
Serial.print(durata2);Serial.print(" Conc25 ");Serial.print(Conc25,1);Serial.println();
TimeOld = millis();
}
}
I have compared the PWM output of the SDS011 sensor (code exposed here) with the results of a Aeroqual 500 series for PM10 and PM2.5 and they gave quite accurate. Actually I am amazed at the accuracy of it.
paolometeo2:
Hi everyone,
I made some comparisons between serial and PWM output from an SDS011 sensor. I found different numbers. I found PWM concentrations about 10 times less than Serial output, both for 10 and 2.5.
Did anyone find the same thing?
I used an Arduino UNO for both outputs. My code follows:
#define SSRxPin 4
#define SSTxPin 3
#define PIN10 6
#define PIN25 5
#define PAYLOAD_LEN 8
#include <SoftwareSerial.h> // comunicazione con Feather
SoftwareSerial mySerial(SSRxPin, SSTxPin); //RX, TX verso ARduino
byte received[PAYLOAD_LEN];
byte i = 0;
byte ch = ' ';
byte flag = 0;
float PM10 = 0;
float PM25 = 0;
float TimePassed = 0;
float TimeOld = 0;
float Periodo = 10000;
void setup() {
pinMode(SSTxPin, OUTPUT);
pinMode(SSRxPin, INPUT);
while(!mySerial);
mySerial.begin(9600);
delay(1000);
while(!Serial);
Serial.begin(115200); // non minore di questa altrimenti si disincronizza
delay(1000);
Serial.println(" ProvaSDS011_Serial_PWM.ino");
}
void loop() {
if(mySerial.available() > 0){
ch = mySerial.read();
Serial.print(ch,HEX);Serial.print(" ");
if(flag){
received[i] = ch;
i++;
}
if(ch == 0xAA && !flag){
flag = 1;
i = 0;
}
if(ch == 0xAB && flag){
flag = 0;
Serial.println();
for(i = 0;i < PAYLOAD_LEN; i++){
Serial.print(received[i]);Serial.print(" ");
}
Serial.println();
int check = received[1]+received[2]+received[3]+received[4]+received[5]+received[6];
check = check % 256;
if(check != received[7]){
Serial.println(" ERRORE ");
}
Serial.print(" check ");Serial.println(check);
PM25 = float(received[2])*256.0 + float(received[1])/10.0;
PM10 = float(received[4])*256.0 + float(received[3])/10.0;
Serial.print(" PM10 ");Serial.print(PM10,1); Serial.print(" PM25 ");Serial.println(PM25,1);
}
}
TimePassed = millis()-TimeOld;
if(TimePassed > Periodo){
unsigned long durata1 = pulseIn(PIN10,HIGH,150000000);
// delay(5000);
unsigned long durata2 = pulseIn(PIN25,HIGH,150000000);
float Conc10 = float(durata1)/1000.0 - 2; //Conc in ug/m3
float Conc25 = float(durata2)/1000.0 - 2; //Conc in ug/m3
if(Conc10 < 0)Conc10 = 0;
if(Conc25 < 0)Conc25 = 0;
Serial.print(" ");Serial.print(durata1);Serial.print(" Conc10 ");
Serial.print(Conc10,1);Serial.print(" ");
Serial.print(durata2);Serial.print(" Conc25 ");Serial.print(Conc25,1);Serial.println();
TimeOld = millis();
}
}