Temperature & Humidity Using Arduino & DHT11

0
942

Adding humidity and temperature data to your DIY electronics projects is a breeze with the DHT11 humidity and temperature sensor. It’s perfect for weather stations in remote locations, home environmental management systems, and farm and garden monitoring.

I’ll give some history on humidity before describing how the DHT11 measures humidity in this tutorial. Then I’ll teach you how to connect the DHT11 to an Arduino and provide you with some sample code to use in your own projects.

The relative humidity (RH) of air is sensed, measured, and reported by the humidity sensor, which also detects the amount of water vapour present in a gas mixture (air) or pure gas. The mechanism of water adsorption and desorption is linked to humidity sensing. Sensors that measure humidity are used to monitor both industrial and agricultural products. Humidity sensors can be found in a lot of different things, like incubators, sterilisers, and pharmaceutical manufacturing machines.

The DHT11 is a basic digital temperature and humidity sensor with a modest price tag. It measures the ambient air with a capacitive humidity sensor and a thermistor and outputs a digital signal on the data pin (no analogue input pins needed). It’s simple to use, but data collection necessitates careful timing.

The DHT11’s ranges and accuracy are as follows

  • Humidity range: 20-95 percent relative humidity

  • Accuracy of humidity: 5% RH

  • Temperature range: 0 to 50 degrees Celsius

  • Temperature Accuracy: +/- 2% °C

  • Voltage range: 3V to 5.5V

ARDUINO UNO

The Uno is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with an AC-to-DC adapter or battery to get started.


Hardware

Hardware Connections

DHT11 Sensor Arduino Connection

VCC- Arduino 5V

GND- Arduino Gnd

DATA- Arduino Pin-2

OLED I2C Display Arduino Connection

  • VCC- Arduino 5V
  • GND- Arduino Gnd
  • SCL- Arduino Pin-A5
  • SDA- Arduino Pin-A4

12V Power Supply Connection

SMPS Input Power

  • Connect To 110-240V AC Power

SMPS Output Power

  • 12V- Connect To Arduino VIN Pin
  • GND- Connect To Arduino GND Pin

Project Code

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#include <Adafruit_Sensor.h>
#include "DHT.h"#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1
Adafruit_SH1106 display(OLED_RESET);
#define DHTPIN 2 // Digital pin connected to the DHT sensor
// Uncomment the type of sensor in use:
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
}
void loop()
{
delay(5000);
//read temperature and humidity
float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
}
//clear display
display.clearDisplay();
// display temperature
display.setTextSize(1);
display.setCursor(0,0);
display.print("Temperature: ");
display.setTextSize(2);
display.setCursor(0,10);
display.print(t);
display.print(" ");
display.setTextSize(1);
display.cp437(true);
display.write(167);
display.setTextSize(2);
display.print("C");
// display humidity
display.setTextSize(1);
display.setCursor(0, 35);
display.print("Humidity: ");
display.setTextSize(2);
display.setCursor(0, 45);
display.print(h);
display.print(" %");
display.display();
}

Download Arduino Library files

Download All Library Files


                                 Project Video

LEAVE A REPLY

Please enter your comment!
Please enter your name here