Skip to content
Snippets Groups Projects
Commit 19fe3e52 authored by Christian Georg Strippel's avatar Christian Georg Strippel
Browse files

Add new file (program for using SDS011 sensor with Arduino Uno and I2C display

parent 262fdd4f
No related branches found
Tags 4.5.1
No related merge requests found
#include <SdsDustSensor.h>
#include <LiquidCrystal.h>
// LCD setup
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
int rxPin = 12;
int txPin = 13;
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
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.setCursor(0, 0); // move cursor to (0, 0)
}
void loop() {
PmResult pm = sds.readPm();
if (pm.isOk()) {
lcd.setCursor(0, 0);
lcd.print("PM2.5 = ");
lcd.print(pm.pm25);
lcd.setCursor(1, 1);
lcd.print("PM10 = ");
lcd.print(pm.pm10);
} else {
// notice that loop delay is set to 0.5s and some reads are not available
lcd.print("Could not read values from sensor, reason: ");
lcd.print(pm.statusToString());
}
delay(1000);
lcd.clear();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment