// PRP 4 — temperature and humidity, plotted over time. // Requires the DHT sensor library. // // The DHT22 needs at least 2 seconds between reads. Sampling faster // returns stale values or nan — it is the most common cause of both. #include const int DHT_PIN = 2; DHT dht(DHT_PIN, DHT22); void setup() { Serial.begin(9600); dht.begin(); } void loop() { float humidity = dht.readHumidity(); float tempC = dht.readTemperature(); if (isnan(humidity) || isnan(tempC)) { Serial.println("read failed"); // check wiring, and check you waited 2s } else { Serial.print(tempC); Serial.print(" "); Serial.println(humidity); // two values, space separated, for the plotter } delay(2000); // minimum sampling interval for this sensor }