Tauno Erik
Published © CC BY-SA

Using SDS011 Dust Sensor

Introduction how to use dust sensor with ESP8266.

BeginnerProtip1 hour3,736
Using SDS011 Dust Sensor

Things used in this project

Hardware components

SDS011 Air Quality Sensor Module
×1
D1 Mini Node MCU Lua WiFi ESP8266
×1
830 Point Solderless Breadboard
×1

Software apps and online services

Arduino IDE
Arduino IDE
PlatformIO IDE
PlatformIO IDE

Story

Read more

Schematics

ekraanipilt_2020-07-10_16-24-59_RSmGLGsaAU.jpg

Code

Code snippet #1

C/C++
#include <Arduino.h>
#include <SdsDustSensor.h>

/* SDS011 Dust Sensor */
const int SDS_RX_PIN = D3; // D3 -> SDS011 TX pin
const int SDS_TX_PIN = D4; // D4 -> SDS011 TX pin
SoftwareSerial softwareSerial(SDS_RX_PIN, SDS_TX_PIN);
SdsDustSensor sds(softwareSerial); //  additional parameters: retryDelayMs and maxRetriesNotAvailable

const int MINUTE = 60000;
const int WAKEUP_WORKING_TIME = 30000; // 30 seconds.
const int MEASUREMENT_INTERVAL = 5 * MINUTE;

void setup() {
  Serial.begin(115200);

  Serial.println("SDS011 dust sensor");
  delay(MINUTE);

  /* SDS011 Dust Sensor */
  sds.begin();
  // Prints SDS011 firmware version:
  Serial.print("SDS011 ");
  Serial.println(sds.queryFirmwareVersion().toString()); 
  // Ensures SDS011 is in 'query' reporting mode:
  Serial.println(sds.setQueryReportingMode().toString()); 
}

void loop() {

  // Wake up SDS011
  sds.wakeup();
  delay(WAKEUP_WORKING_TIME);

  // Get data from SDS011
  PmResult pm = sds.queryPm();
  if (pm.isOk()) {
    Serial.print("PM2.5 = ");
    Serial.print(pm.pm25); // float, μg/m3

    Serial.print(", PM10 = ");
    Serial.println(pm.pm10);

  } else {
    Serial.print("Could not read values from sensor, reason: ");
    Serial.println(pm.statusToString());
  }

  // Put SDS011 back to sleep
  WorkingStateResult state = sds.sleep();
  if (state.isWorking()) {
    Serial.println("Problem with sleeping the SDS011 sensor.");
  } else {
    Serial.println("SDS011 sensor is sleeping");
    delay(MEASUREMENT_INTERVAL);
  }
}

Github

https://github.com/lewapek/sds-dust-sensors-arduino-library

Credits

Tauno Erik

Tauno Erik

15 projects • 23 followers
learning somthing new

Comments