Introduction

Sometimes, you will want to be able to read both the temperature and humidity in your surroundings. 

In this guide, you will learn how to use a DHT11 temperature and humidity sensor with the Arduino. 

Doing so will enable you to progress onto working on further projects such as a greenhouse control device or a DIY weather station.
    • Insert the DHT11 Into the Breadboard

    • Bridge DHT11 Pin 1 and Pin 2 with a 10K Resistor.

    • This resistor will pull up the signal line.

    • Connect Ground to the DHT11

    • Connect 5V to the DHT11

    • Connect the DHT11 to Digital Pin 2

    • Install the SimpleDHT Library.

  1. #include <SimpleDHT.h>
    
    // for DHT11,
    //      VCC: 5V or 3V
    //      GND: GND
    //      DATA: 2
    int pinDHT11 = 2;
    SimpleDHT11 dht11;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      // start working...
      Serial.println("=================================");
      Serial.println("Sample DHT11...");
    
      // read without samples.
      byte temperature = 0;
      byte humidity = 0;
      int err = SimpleDHTErrSuccess;
      if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
        Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
        return;
      }
    
      Serial.print("Sample OK: ");
      Serial.print((int)temperature); Serial.print(" *C, ");
      Serial.print((int)humidity); Serial.println(" H");
    
      // DHT11 sampling rate is 1HZ.
      delay(1500);
    }
    • Upload this code to your Arduino

    • Open your Serial Port and look at the Temperature and Humidity!

    • Be sure to be using a Baud rate of 9600.

    • Breath on your Sensor and look at what happens!