electroSome

Interfacing DHT11 Temperature and Humidity Sensor with Arduino Uno

DHT11 Temperature and Humidity Sensor Module

DHT11 Temperature and Humidity Sensor Module

Contents

In this tutorial we will learn about Interfacing DHT11 Temperature and Humidity sensor with Arduino Uno. The term DHT is an abbreviation of Digital Humidity and Temperature sensor. DHT11 consists of a resistive humidity sensor, NTC temperature sensor and an 8-bit microcontroller providing cost effectiveness, anti-interference ability, excellent quality and fast response.

Components Required

DHT11 Temperature and Humidity Sensor

DHT11 Temperature and Humidity Sensor Module – PIN Diagram

Specifications

Working

Circuit Diagram

Description

Program

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"

#define DHTPIN 2     
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup()   {                
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C
    display.display(); // show splash screen
    delay(2000);
    display.clearDisplay();   // clears the screen and buffer
    dht.begin();
    delay(2000);
}

void loop() {
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();
    // Read temperature as Fahrenheit (isFahrenheit = true)
    float f = dht.readTemperature(true);

    // Check if any reads failed.
    if (isnan(h) || isnan(t) || isnan(f)) {
        delay(2000);
    } 
    else {
        // routine for converting temp/hum floats to char arrays
        char temp_buff[5]; char hum_buff[5];
        char temp_disp_buff[11] = "Tmp:";
        char hum_disp_buff[11] = "Hum:";
    
        // appending temp/hum to buffers
        dtostrf(t,2,1,temp_buff);
        strcat(temp_disp_buff,temp_buff);
        dtostrf(h,2,1,hum_buff);
        strcat(hum_disp_buff,hum_buff);
    
        // routine for displaying text for temp/hum readout
        display.clearDisplay();
        display.setTextSize(2);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.println(temp_disp_buff);
        display.println(hum_disp_buff);
        display.display();
        delay(2000);
    }
}

Functioning

Practical Implementation

Video

Conclusion

Hope you understand the working of DHT11 temperature and humidity sensor and how to integrate it with Arduino Uno. Also about integrating SSD1306 OLED display with Arduino Uno. Please feel free to comment below if you have any doubts.

Exit mobile version