Ardumotive Arduino Greek Playground
  • Home
    • About us
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

DHT-22

                          26/9/2018
Available Languages
Picture
Picture

Introduction 

Picture
The DHT-22 (also named as AM2302) is a digital-output relative humidity and temperature 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.

In this tutorial you will learn how to use the DHT-22 sensor with Raspberry Pi.

Let's get started!

About the  DHT-22 sensor

The DHT22 is a basic, 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 (no analog input pins needed).
Connections are simple, the first pin on the left to 3.3V power, the second pin to your data input pin and the right most pin to ground.
Picture
Technical details:
  • Power: 3-5V
  • Max Current: 2.5mA
  • Humidity: 0-100%, 2-5% accuracy
  • Temperature: -40 to 80°C, ±0.5°C accuracy

What you will need - Hardware

For this tutorial you will need:
  • GPIO Breakout(optional)
  • Breadboard
  • DHT-22
  • 10KΩ resistor
Picture

The Circuit

Picture
The connections are pretty easy, see the image above with breadboard circuit schematic.

Install Adafruit DHT library

Before python code you need to download and install the DHT library in your Raspberry Pi. Open the terminal window and type:
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo apt-get update
sudo apt-get install build-essential python-dev
sudo python setup.py install
Now you will have to reboot your Pi system to get the Adafruit driver.

Python code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#Libraries
import Adafruit_DHT as dht
from time import sleep
#Set DATA pin
DHT = 4
while True:
    #Read Temp and Hum from DHT22
    h,t = dht.read_retry(dht.DHT22, DHT)
    #Print Temperature and Humidity on Shell window
    print('Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(t,h))
    sleep(5) #Wait 5 seconds and read again
Download the code from here and open it with Thonny Python IDE  or run it from terminal.
dht22tutorial.zip
File Size: 0 kb
File Type: zip
Download File

Well Done

You have successfully completed one more Raspberry Pi "How to" tutorial and you learned how to use the DHT-22 sensor.
I hope you liked this, let me know in the comments.

Video in Greek language

Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates