One of the new features of Arduino1.6.6 is the ability to plot data. In this example, I have taken a DHT-11 temperature sensor, and I’m sending the data to the serial plotter (found on the Tools menu). You can only have one axis of data, so I have a single serial.println in the code.
I’m using a DHT-11 module that comes on a breakout board with the resistor all ready added. You will need the DHT library found at https://github.com/adafruit/DHT-sensor-library. I plugged the module directly into the Arduino, so the data pin is connected to Arduino pin 6, – is connected to Arduino Pin 7, and +5 is connected to pin 5. You will see in the code where I’m sending digitalWrite commands to pins 5 and 7 sending a high and a low respectively, powering the module. Because I’m taking a reading every 2 seconds (it’s a slow sensor) the serial plotting crawls very slowly across the screen.
Become the Maker you were born to be. Try Arduino Academy for FREE!
#include "DHT.h"
#define DHTPIN 6 // what digital pin we’re connected to
// Uncomment whatever type you’re using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
pinMode(7, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(7, LOW);
digitalWrite(5, HIGH);
//Serial.println(“DHTxx test!”);
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
//Serial.println(“Failed to read from DHT sensor!”);
return;
}
Serial.println(f);
}