How to Set Up Temperature and Humidity Sensor (DHT11) on Raspberry Pi

Byamber

How to Set Up Temperature and Humidity Sensor (DHT11) on Raspberry Pi

DHT11 sensor which can measure temperatures& relative humidity .The sensor uses its own proprietary 1-wire protocol to communicate with Raspberry Pi and runs from 3.3V-5V. The timings must be precise and according to the datasheet of the sensor.

Circuit:-

Holding the DHT11 towards you (the one with grid), the left pin is connected to VCC (pin 1).The data pin is next  after VCC and is connected to pin 7.Next pin is NC(no connection).Finally the last pin is connected to GND(pin 25).To prevent random data connect a 10K resistor between data and VCC pin of DHT11.

pi-dh11
Software:-
WiringPi which uses C like Arduino language is used to read the sensor value. WiringPi is maintained under GIT for ease of change tracking.If you do not have GIT installed, then under any of the Debian releases, you can install it with-
sudo apt-get install git-core

To obtain WiringPi using GIT:
git clone git://git.drogon.net/wiringPi

If you have already used the clone operation for the first time, then
cd wiringPi
git pull origin
Will fetch an updated version then you can re-run the build script below.

To build/install there is a new simplified script:
cd wiringPi
To creat and open new file: sudo nano temp_rh_sensor.c

Copy the below code to temp_rh_sensor.c file and press Ctrl + X key,then press Y to save file:

http://osoyoo.com/driver/temp_rh_sensor.c

Also You can input below command to download the temp_rh_sensor.c file directly.

sudo wget --no-check-certificate   http://osoyoo.com/driver/temp_rh_sensor.c
Compile the code as…
gcc -o sensor temp_rh_sensor.c -L/usr/local/lib -lwiringPi
Now execute it…
sudo ./sensor
QQ图片20170414184725

About the Author

amber administrator

You must be logged in to post a comment