Measure Temperature and Humidity with Arduino

Arduino humidity and temperature sensor

It is actually very easy to measure the humidity and Temperature with an Arduino and the DHT22 sensor. We will only need three wires and just a little code. This sensor is available in our sensor kit, which is a kit that includes many useful sensors for your projects.

First of all, we will be connecting everything. This step is made very easy for us, because the sensor is wired up internally. After plugging your sensor into a breadboard, connect the left most wire to any digital pin on your Arduino, the middle wire to 5V and the right one to GND like in the picture below.

How to connect and wire up a Temperature and Humidity sensor with Arduino.

Programming the Arduino is even easier than hooking up all of the electronics. You will just have to download the DHT library and use all of their commands. We first include the library and tell it with #define DHT11_PIN 7 that we are using pin 7 for our data transfer. Then we start serial communication so we can print out the Temperature and Humidity.

#include <dht.h>//Including the library.
dht DHT;
#define DHT11_PIN 7 //We use pin 7 for the data

 void setup(){
   Serial.begin(9600);//Starting serial communication to be able to print text.

The next piece of code is in a loop, ensuring that the data is printed every second. The first thing we need to do is read the sensor data, which we do with a library command. Then we print everything out and take the data from the library with the DHT.temperature command. Lastly, we wait a second with the delay(1000) command.

void loop(){
    int chk = DHT.read11(DHT11_PIN);// Reading the data
    Serial.print("Temperature = ");
    Serial.print("Humidity = ");

After writing your code, upload it to the Arduino and you should now see the Temperature and Humidity in the serial monitor.

Leave a Reply