From stick to strip
5. The serial plotter
We will now amend the previous sketch in order to plot temperature and heat index on the computer offline:
#include "DHT.h"
#define DHTPIN 2 // what digital pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(t)) {
return;
}
Serial.println(t);
}
Now open Tools > Serial Plotter and see the temperature plot of the real-time sensor data. This feature is very handy when debugging sensors with Arduino.
You can also plot more than one variables at a time, by seperating them with a
Serial.print(" ");
.