Sign In SIGN UP UPGRADE

Arduino + DHT22 Temperature and Humidity Sensor

DHT22 Temperature and Humidity Sensor splash image

Getting started

Arduinos are fantastic. One of their greatest strengths is the simplicity with which they interface with so many sensors! We'll show you how to start plotting your Arduino's sensor data using the Ethernet shield. Just follow along, and if you have any trouble, don't hesistate to reach out to the Plotly Community!

Materials

  • Arduino-compatible board
  • Your choice of Arduino internet shield
    (WIFI, CC3000, Ethernet, GSM)
  • DHT22 temperature + Humidity sensor
  • Hookup wires
DHT22 Temperature and Humidity Sensor Parts

Hooking it up

DHT PIN1 Arduino 5V
DHT PIN2 10K Resistor Arduino 5V
DHT PIN2 Arduino Digital Pin 2
DHT PIN3 Not Used
DHT PIN4 Arduino GND

DHT22 Temperature and Humidity Sensor hookup

Software

Download and install all libraries into your usual Arduino Library Folder.
The default is usually at /User/Documents/Arduino/Libraries.

If you're using the Arduino wifi shield, make sure to use version 1.0.3 of the Arduino IDE!

The script

Grab the Arduino sketch here:

Open up dht22.ino and let's go through it. First we initialize a plotly graph. If you're using a wifi shield, remember to change these wireless credentials to your own in the sketch!

plotly graph("username", "api_key", tokens, "filename", nTraces);

In the setup() function, we're going to initialize the graph. Once it's initialized, we're going to open the stream. graph.openStream() opens the plotly stream and graph.plot() is where all the data gets piped in. Let's check it out:

graph.init();
graph.openStream();

In the loop() function, we're going to start streaming our sensor data!

void loop() {
    int dht22_reading = analogRead(dht22_pin);
    graph.plot(millis(), dht22_reading, tokens[0]);
}

Your code is now all set up!

Wrapping it up

By now you've got your Arduino wired up to the DHT22 sensor, you've got it set up for internet connectivity, you've uploaded your sketch, and you're ready to go.

Start streaming! Plug in your Arduino, and go check out your live results!