Nova Fitness Sds dust sensors library: an example that runs
Yes. You can use the Nova Fitness Sds dust sensors library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Dust sensor, SDS011). The example below, "Read an SDS011 dust sensor in active reporting mode", runs on the Arduino Uno R3.
Built in on Mokxi: #include <SdsDustSensor.h> and it builds, with nothing to install. Free, and no account needed.
What Nova Fitness Sds dust sensors library does
SdsDustSensor sds(serial or rx, tx pins): readPm() and queryPm() for PM2.5 and PM10, the reporting mode, working period, sleep and wakeup, and the firmware version, each a result with its status. That is what Nova Fitness Sds dust sensors library, by Paweł Kołodziejczyk, covers. The sketch below uses it on the Arduino Uno: “Read an SDS011 dust sensor in active reporting mode”.
Paweł Kołodziejczyk's Nova Fitness Sds dust sensors library's interface, for the SDS011 (and SDS018, SDS021) laser PM2.5 and PM10 sensors on a serial port.
The result classes print what upstream's do. No dust level is made up.
The calls follow release 1.5.1 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.
| Library Manager name | Nova Fitness Sds dust sensors library |
|---|---|
| Author | Paweł Kołodziejczyk |
| Include | #include <SdsDustSensor.h> |
| Boards | Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ESP8266 NodeMCU, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Dust sensor, SDS011 |
Install it
It builds on Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ESP8266 NodeMCU, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32.
In Mokxi it is built in: #include <SdsDustSensor.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Nova Fitness Sds dust sensors library" by Paweł Kołodziejczyk from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Nova Fitness Sds dust sensors library to lib_deps in PlatformIO. Mokxi follows the calls of release 1.5.1, so a sketch written here builds there too.
What to know in the simulator: Talks to the SDS011 part: its real 10 byte frames once a second, the query, sleep, working period and firmware commands, and the results upstream prints. Each command waits 500 ms after it is written, as upstream. The pins constructor needs SoftwareSerial (the ATmega boards, the ESP8266, the classic ESP32 and the S3).
The calls you will use
In the order a sketch meets them.
SdsDustSensor sds(rxPin, txPin)
Makes sds, the SdsDustSensor object the calls below are made on.
sds.begin()
Starts it up. Call it once in setup(). Arguments: baud rate.
sds.queryFirmwareVersion()
Returns the firmware version as a FirmwareVersionResult.
sds.setActiveReportingMode()
Sets the active reporting mode.
sds.setContinuousWorkingPeriod()
Sets the continuous working period.
PmResult pm
Makes pm, the PmResult object the calls below are made on.
sds.readPm()
Returns the pm as a PmResult.
pm.isOk()
Returns true or false for "is ok".
Example: Read an SDS011 dust sensor in active reporting mode
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include "SdsDustSensor.h"
int rxPin = 2;
int txPin = 3;
SdsDustSensor sds(rxPin, txPin);
void setup() {
Serial.begin(9600);
sds.begin();
Serial.println(sds.queryFirmwareVersion().toString()); // prints firmware version
Serial.println(sds.setActiveReportingMode().toString()); // ensures sensor is in 'active' reporting mode
Serial.println(sds.setContinuousWorkingPeriod().toString()); // ensures sensor has continuous working period - default but not recommended
}
void loop() {
PmResult pm = sds.readPm();
if (pm.isOk()) {
Serial.print("PM2.5 = ");
Serial.print(pm.pm25);
Serial.print(", PM10 = ");
Serial.println(pm.pm10);
// if you want to just print the measured values, you can use toString() method as well
Serial.println(pm.toString());
} else {
// notice that loop delay is set to 0.5s and some reads are not available
Serial.print("Could not read values from sensor, reason: ");
Serial.println(pm.statusToString());
}
delay(500);
}Wiring
- Arduino Uno R3 2 to Dust sensor, SDS011 TX
- Arduino Uno R3 3 to Dust sensor, SDS011 RX
- Arduino Uno R3 5V to Dust sensor, SDS011 5V
- Arduino Uno R3 GND to Dust sensor, SDS011 GND
Projects that use Nova Fitness Sds dust sensors library
Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.
Try Nova Fitness Sds dust sensors library without installing anything
Open the example, change the sketch, and keep your version in a free account.