DHT11 Sensors Temperature and Humidity Tutorial using Arduino

in #utopian-io8 years ago (edited)

What Will I Learn?

In this instructable we will learn how the DHT11 emperature and Humidity works with arduino, how to connect the module to arduino and how to add the library to arduino desktop IDE.

20180127_182258.jpg

Requirements

We need this couple of components in this activity.

  • DHT11 Sensor Module
  • Arduino Board
  • Jumper wires
  • Type b usb cable
  • Breadboard

Difficulty

  • Basic

Tutorial Contents

The DHT11 is a ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin on the digital pin on the arduino. Its fairly simple to use, but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds per sensing. of you re going to test the sensor follow the fritzing breadboard diagram that i made.

frit.png

DHT11 Connection pin

  • VCC - 5V
  • GND - GND
  • SENSOR - 5

20180127_181638.jpg

SOFTWARE

We are done building the circuit so lets start to set up and make a code for this. we are going to use the arduino ide, to set the sketch for this, if you dont have make sure to download the Arduino IDE for your specific operating system. I’ll leave a link to where you can download this software: https://www.arduino.cc/en/Main/Software

ardy.png

I have the IDE downloaded to my computer so lets start to work for the libraries we have to download the DHT11 libraries here; https://github.com/adafruit/DHT-sensor-library

dl.png

When the download is finished open the zip file then copy the folder unzip the folder to your desktop you can rename it as well.

desk.png

Cut the folder in your desktop then go to your folders then locate the arduino folder>> libraries then paste it there. and now the folder for DHT library is already in the arduino ide libraries.

paste.png

We gave another way to download the DHT library base on the IDE just locate the SKEtCH>> INCLUDE LIBRARY<<>>MANAGE LIBRARY<< on the search bar. search for the DHT libary then click download.

dht.png

After the download has finished locate the>> FILE<<>>click EXAMPLES>>DHT SENSOR LIBRARY<<>>then DHTTESTER.>>

addlib.png
A new .ino file for DHT tester will apear plug in the sensor pin to the right pin output base on the code ,
image.png

CODE ExPLANATION

When making code at the first line we need include the DHT library by inputing #include "DHT.h" the h file is a file inside the DHT library folder files,
#define DHTPIN 2 Define DHT pin this the pin where the sensor pin of the DHT is connected to the digital pin 2 on the arduino board.
#define DHTTYPE DHT11 Define the DHT type, theres another upgraded DHT sensor module which is the DHT22 on this tutorial were using the DHT11.
DHT dht; define the uppercase DHT to dht in lowercase to recognized that the lower case is the same as upper case on the same state.
setup() method is ran once at the just after the Arduino is powered up and the loop() method is ran continuously afterwards.
setup() is where you want to do any initialisation steps, and in loop() you want to run the code you want to run over and over again.
Serial.print the iput text word that appears on the serial monitor or lcd display.

COPY CODE HERE

#include "DHT.h"
#define DHTPIN 2     
#define DHTTYPE DHT11   // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");
  dht.begin();
}
void loop() {
  // Wait a few seconds between measurements.
  delay(2000);
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  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 and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}


20180127_182220.jpg

The RED light should glow means the sensor is powered on. now open the serial monitor to check the current temperature and humidity captured by the sensor.

com.png

The Humidity,Temperature, and Heat index should appear on the serial monitor. I hope you enjoy this actitvity if want to learn how arduino works, and how to make a sketch, then maybe this site http://educ8s.tv/ might help you. thank you

You can also check my previous posts:


Control LED using Push Buttons/ Visual programming using XOD
Control Servo motor using Joystick
Stepper motor + Driver Uln2003 in arduino
Control Servo motor using potentiometer - arduino



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

  • D11 temperature tutorial is available Here
  • Also, you already had temperature tutorial earlier. I know the application or software’s were different. But it really makes no sense to make two.

You can contact us on Discord.
[utopian-moderator]

@pakganern, I like your contribution to open source project, so I upvote to support you.

its a informational post.i knew something from it.good artical.thanks

Coin Marketplace

STEEM 0.04
TRX 0.33
JST 0.098
BTC 64443.02
ETH 1870.82
USDT 1.00
SBD 0.38