Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple ESP32/Arduino program for reading the SDS-011 output in continuous mode
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, -1, -1, false);
}
void loop() {
if (Serial2.available()) {
byte pm_buf[10];
Serial2.readBytes(pm_buf, 10);
unsigned int pm_25_count = 0;
pm_25_count = pm_buf[3] << 8;
pm_25_count |= pm_buf[2];
float pm_25 = (float) pm_25_count / 10.0f;
unsigned int pm_10_count = 0;
pm_10_count = pm_buf[5] << 8;
pm_10_count |= pm_buf[4];
float pm_10 = (float) pm_10_count / 10.f;
Serial.printf("PM2.5 = %.4f; PM10 = %.4f\n", pm_25, pm_10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.