// PDD42 op poort D8 // RGB LCD op I2C //Librarie: // Wire.h Adafruit DS248x voor I2C communicatie // Grove Temperature and Humidy Sensor *Seeed Studio) // Grove LCD RGB Backlight (seeed Studio) #include #include "rgb_lcd.h" #define PPD_PIN 8 rgb_lcd lcd; unsigned long lowpulseoccupancy = 0; unsigned long starttime; unsigned long sampletime_ms = 30000; // 30 seconden voor stabiele meting void setup() { Serial.begin(115200); pinMode(PPD_PIN, INPUT); Wire.begin(); // Initialiseer het LCD direct lcd.begin(16, 2); lcd.setRGB(0, 0, 255); // Blauw tijdens opwarmen lcd.print("Opwarmen..."); starttime = millis(); } void loop() { // Meet de tijd dat het signaal laag is (Low Pulse Occupancy) lowpulseoccupancy += pulseIn(PPD_PIN, LOW); if ((millis() - starttime) > sampletime_ms) { // Berekening stofconcentratie float ratio = lowpulseoccupancy / (sampletime_ms * 10.0); float concentration = 1.1 * pow(ratio, 3) - 3.8 * pow(ratio, 2) + 520 * ratio + 0.62; lcd.clear(); lcd.setCursor(0, 0); lcd.print("pcs Conc: "); lcd.print(concentration, 1); // Kleur instellen op basis van concentratie lcd.setCursor(0, 1); if (concentration < 1000) { lcd.setRGB(0, 255, 0); // Groen (Schoon) lcd.print("Lucht: Goed"); } else if (concentration < 5000) { lcd.setRGB(255, 100, 0); // Oranje (Matig) lcd.print("Lucht: Matig"); } else { lcd.setRGB(255, 0, 0); // Rood (Slecht) lcd.print("Lucht: Slecht"); } // Reset voor volgende meting lowpulseoccupancy = 0; starttime = millis(); } }