DHT11 Temperature and Humidity Sensor with Raspberry Pi | PythonSharath
DHT11 is one of the most used Temperature and Humidity Sensor. It is cheap, compact and provides a reliable data, it is best for a DIY electronics projects.
The DHT11 can measure Temperature between 0 to 50° C with ±2 °C accuracy. It can measure Humidity between 20 to 80% with ±5% accuracy. The sampling rate of DHT11 is 1 HZ which is 1 reading per second. The Operating Voltage of DHT11 is 3 to 5V and uses a 2.5 mA of maximum current while operating.
The DHT11 Temperature and Humidity Sensor consist of 3 main components. A resistive type humidity sensor, an NTC (negative temperature coefficient) thermistor (to measure the temperature) and an 8-bit microcontroller, which converts the analog signals from both the sensors and sends out single digital signal.
Distance up to 20 m**
How DHT11 Measures Temperature?
For measuring Temperature the sensor uses an NTC Thermistor. A Thermistor is a variable resistor that changes its resistance to the change in temperature. The NTC means Negative Temperature Coefficient which means resistance decreases as temperature rises.
A thermistor is made of metallic oxides which is pressed into a bead, disk, or cylindrical shape and then encapsulated with an impermeable material such as epoxy or glass.
How DHT11 Measures Humidity?
The Humidity is measured by the electrical resistance between two electrodes. The humidity sensing component of the DHT11 is a moisture holding substrate (usually a salt or conductive plastic polymer) with the electrodes applied to the surface. The ions are released by the substrate as water vapor is absorbed by it, which in turn increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity.
Note: There are different DHT11 modules available in the Market. Make sure the Signal, VCC and Ground are properly connected to Raspberry Pi. The OUT pin is mentioned as SIG in few modules and also the position of pin varies.
Here we have the DHT11 with VCC-OUT-GND. So we connected the middle pin to Raspberry Pi 23rd GPIO Pin.
|DHT11 Sensor||Raspberry Pi|
DHT11 using AdaFruit DHT11 Library for Raspberry Pi:
Adafruit developed a simple library to use DHT11 with Python. So we need to install the library from GitHub. Before that, we need to install Git if you are not installed.
Step 1: Open the terminal and use the following command to install Git.
sudo apt-get install git-core
Step 2: Now we need to install the Adafruit DHT11 Library. Use the command to download the Adafruit DHT11 Library from Git.
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
Step 3: Now navigate to the ‘Adafruit_Python_DHT11’ directory using the following command.
Step 4: Now enter this command
sudo apt-get install build-essential python-dev
Step 5: Install the Adafruit DHT11 library now.
sudo python setup.py install
Step 6: Now we need to configure the Pin for Pi.
Navigate to the example file using the command
Step 7: Open the file using nano editor.
This will open the text editor. Choose the pin you connected the DHT11 with Raspberry Pi.
By default, it is selected for BeagleBone. So Change the Pin for Pi by comment (put #) the Beaglebone Pin and Uncomment (remove #) the Raspberry Pi GPIO Pin.
Save the File by pressing ‘Ctrl X’. Then press y to save.
Step 8: Now run the file by using the command,
You can able to see the Temperature and Humidity in the terminal.