Hello, I am testing the DSM501A sensor and using NodeMCU ESP8266, usually getting values equal to -0.5 mg/m3, but sometimes these values go up to 0.02 mg/m3 and even 0.5 mg/m3.
I sincerely doubt the veracity of the last information mentioned. I placed the sensor on a desk that is next to an air conditioner, about a meter and a half away.
At the end of the day I would like to use this sensor to check the concentration of dust and pollen.
Below I am attaching the datasheet and code I am using.
Datasheet: https://www.elektronik.ropla.eu/pdf/stock/smy/dsm501.pdf
#include<string.h>
#define PM25PIN D7 //el pin 4 del DSM501A
byte buff[2];
//unsigned long durationPM1;
unsigned long durationPM25;
unsigned long starttime;
unsigned long endtime;
unsigned long sampletime_ms = 30000;
unsigned long lowpulseoccupancyPM25 = 0;
int i=0;
void setup()
{
Serial.begin(9600);
Serial.println("Starting please wait 30s");
pinMode(PM25PIN,INPUT);
starttime = millis();
}
float calculateConcentration(long lowpulseInMicroSeconds, long durationinSeconds){
float ratio = (lowpulseInMicroSeconds/1000000.0)/30.0*100.0;
float concentration = 0.001915 * pow(ratio,2) + 0.09522 * ratio - 0.04884;//esta en mg/m3
Serial.print("lowpulseoccupancy:");
Serial.print(lowpulseInMicroSeconds);
Serial.print(" ratio:");
Serial.print(ratio);
Serial.print(" Concentration:");
Serial.println(concentration);
return concentration;
}
void loop()
{
durationPM25 = pulseIn(PM25PIN, LOW);
lowpulseoccupancyPM25 += durationPM25;
endtime = millis();
if ((endtime-starttime) > sampletime_ms) //Only after 30s has passed we calcualte the ratio
{
/*
ratio1 = (lowpulseoccupancy/1000000.0)/30.0*100.0; //Calculate the ratio
Serial.print("ratio1: ");
Serial.println(ratio1);
concentration = 0.001915 * pow(ratio1,2) + 0.09522 * ratio1 - 0.04884;//Calculate the mg/m3
*/
float conPM25 = calculateConcentration(lowpulseoccupancyPM25,30);
float conUG=conPM25*1000;//calculate ug/m3
Serial.print(" PM25 ");
Serial.println(conPM25 +"mg/m3");
Serial.println(String(conUG)+"ug/m3");
lowpulseoccupancyPM25 = 0;
starttime = millis();
}
}