Introduction: Dust Sensor With DSM501a and ESP8266

This instructable will teach you how to connect an ESP8266 to a DSM501a dust sensor.

It will also teach you how to calculate the particles in mg/m3 (metre cube) so that you can use it for AQI measurements.

Supplies

Supplies

  1. DSM501a
  2. ESP8266
  3. Jumper Wires and Connectors

Step 1: Connect Up DSM501a and ESP8266

Connect up the DSM501a and the ESP8266 according to the above diagram.


ESP8266 D6 - DSM501a Line 2 (PM1.0)

ESP8266 D5 - DSM501a Line 4 (PM2.5)

ESP8266 VIN - DSM501a Line 3 (VCC)

ESP8266 GND - DSM501a Line 5 (GND)


For the PM1.0 (Line 2) and PM2.5 (Line 4) all requires PWM lines you can refer to the pinout link below for which pins are PWM on the ESP8266 if you want to change the lines.

https://lastminuteengineers.com/esp8266-nodemcu-arduino-tutorial/

Step 2: Upload the Code

Open the code in Arduino IDE and flash the program into your ESP8266.

Ensure that the settings of the board for your IDE is correct and the correct COM port is selected before uploading.

Open up the Serial Monitor to see the output.


You might need to wait for about 30s before the first output comes out and about a minute for the numbers to stabilize.

Step 3: How Does the DSM501a Work

The DSM501a works by sending out a low pulse that we need to collect over a fixed time period of 30s. We then divide the sum of the low pulses over the fixed time period.


void loop(){
//Reads in the low pulses from the pins
  durationPM1 = pulseIn(PM1PIN, LOW);
  durationPM25 = pulseIn(PM25PIN, LOW);
  ...
  }


For example: We monitor the low pules over 30s and we have 1000ms (1s) of low pulses so we will divide 1/30 that will give us the low ratio.

float ratio = (lowpulseInMicroSeconds/1000000.0)/30.0*100.0; //Calculate the ratio


Need to note, Arduino pulseIn measures in microseconds not milliseconds so to convert to seconds you will need to divide by 1000000. We make it divide by 1000000.0 because without the .0 the division would be an INT which will be mostly 0. By putting an .0 at the end we made the number into a float.

Using the low ratio we can compare to the table and get the mg/m3 reading.

To find the mg/m3 reading using the low ratio in formula you can use the below

concentration = 0.001915 * pow(low_ratio, 2) + 0.09522 * low_ratio - 0.04884;


References

https://www.elecrow.com/wiki/images/3/3a/DSM501.pdf

https://groups.google.com/g/airqualityegg/c/A1F9padoW10?pli=1