How to Set Up the DHT11 Humidity Sensor on the Raspberry Pi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you hey everyone welcome back to another circuit basics video tutorial today I'll be explaining how to set up the dht11 digital humidity and temperature sensor on the Raspberry Pi this is one of my favorite sensors it's really easy to set up it's cheap and it only needs one wire to send data to the PI first I'll show you how to connect it then I'll show you how to use it in programs written in C and Python by the end of the video you'll know how to output the humidity and temperature readings to an SSH terminal like putty and also to an LCD display let's start by connecting the dht11 to the pi so we can get the temperature and humidity output to an ssh terminal I've got a couple bread boards with my PI here I'm going to insert the dht11 into the smaller breadboard now I'm going to insert a jumper wire from the negative pin of the dht11 and connect it to the ground pin of the PI pin 6 all the raspberry pi pin numbers I'll be talking about here are the pin numbers on the board now connect the VCC pin of the dht11 to the 5 volt pin of the PI into then I'll connect the signal pin to the dht11 to pin seven of the pie okay now that's connected let's look at a C program that will get the temperature and humidity from the sensor and output it to an SSH terminal I'm using putty so I'll just log in to my PI here I've got a post on the circuit basics blog with all these sample code and wiring diagrams so you can go there to copy these example programs if you want there are two different variants of the dht11 one is mounted to a PCB and has three pins and the other has four pins and isn't mounted to a PCB the pin dots are different so make sure you connect the pins according to which type you have abusing wiring PI to control the GPIO pins in the C program I'm assuming you already have wiring PI installing your pine if you don't though just Google how to install it there's lots of tutorials that make it really easy I'm going to copy our C program for SSH terminal output of the temperature and humidity readings we need to save this code in a file that has a dot C extension I'll enter sudo nano example about C to create a new file with the dot C extension now just right click to paste that code in there control-x to say exit now we need to compile the example dot C program we can do that with this command right here you now to run the program we can enter sudo dot Ford / example so now the temperature and humidity is being output to the terminal at one-second intervals this shows Celsius and Fahrenheit the humidity is percent relative community Chelsea will exit the program okay now let's check out a C program that will output the temperature and humidity readings to an LCD display first I should show you how to connect the LCD to the PI I'm going to insert my LCD into the larger breadboard now insert a 10k potentiometer for the contrast and another 10k potentiometer for the backlight brightness now connect the jumper wire from the VSS pin of the LCD to the negative rail of the breadboard then I'll connect the VDD pin of the LCD to the positive rail of the breadboard I'll connect the vo pin of the LCD to the underpinning the contrast potentiometer then I'll connect the RS pin to the LCD over to pin 37 of the pi you next i'll connect the RW pin of the LCD over to the negative rail of the breadboard you and the epin of the LCD over to pin 35 of the Raspberry Pi you next I'll connect the data pins in 4-bit mode so we'll only need to use data pins d4 to d7 I'm going to use a ribbon cable you I'm connecting data pindy for the LCD to pin 33 of the pie pindy 5 2 pin 31 of the pie LCD pin d6 to pin 29 of the pie and LCD pin d7 to pin 23 of the pie now I'm going to connect the a pin the second to the last pin of the LCD to the center pin of the backlight brightness potentiometer now take another jumper wire and connect the Cape into the LCD the last pin on the LCD to the ground rail of the breadboard next I'll connect one of the outer pins of the backlight brightness potentiometer to the positive rail of the breadboard it doesn't matter which side you connect it only changes which direction the knob turns increase or decrease the backlight brightness next I'll connect one side of the contrast potentiometer to the negative rail of the breadboard same here the side you choose just determines whether clockwise or counterclockwise turns the knob turn up or down the contrast now connect the positive rail of the breadboard to the 5 volt pin of the PI pin to you and I'll connect the negative rail of the breadboard to the ground pin of the PI and six so now insert the dht11 into the smaller breadboard I'll connect the jumper wire from the five volt pen to the dht11 over to the positive rail the larger breadboard you then I'll connect the ground pin of the dht11 to the negative rail the breadboard now I'll connect the signal pin of the dht11 to pin seven of the pine okay now we're ready to load our C program and get the humidity and temperature readings output to the LCD display here's our example program so I just copy it and instead of re-entering all my commands I can just use the up arrow to show the commands that I use before so let's use my sudo nano example that's C command from before just clear out this old coat with control cane and paste in the LCD code now compile the new code you so now the humidity and temperature readings are displayed on the LCD temperatures in Fahrenheit but if you want Celsius scroll down to line 72 and uncomment it then comment out the line below that save compile and run it now the temperatures in Celsius all right that is programming the dht11 and see now let's program in Python I'll be using the DHT Python library from Adafruit to drive the dht11 there are a few things we need to do to install it the library is downloaded with git so if you don't have git installed in your priority enter sudo apt-get install git - core at the command prompt you now enter this command to download the Adafruit DHT library you after that's finished enter CD Adafruit underscore Python underscore DHT to change directories to where the library was downloaded now enter sudo apt-get install build essential Python dev you okay now we can install the library enter sudo python setup that py install you now we're going to use the dht11 with Python for an example program here that will output temperature and humidity values to an SSH monitor like putty let me just copy this enter CD to get back to the root directory and I'll create a new file with a dot py extension I'll call it example that py now I'll paste that coding here you and enter sudo python example of that py to run the program so now the temperature and humidity readings are printed in the monitor once per second you press control-c to exit the program okay good now let's get those sensor readings to display on LCD we've already connected the LCD in the C programming part so all we need to do is install another Python library to drive the LCD the best Python LCD library I've found is the RP LCD library it's easy to install and it's easy to use - we'll be downloading it from the Python package index or pip if you already have pip installed in your pie just skip this step but if not enter sudo apt-get install Python - pip the command prompt you after pip is installed install the RPL CD library by entering sudo pip install our P LCD okay now let's run this example program I'll just copy this you and paste it into our example program enter sudo python example py to run it you can see here the temperature is displayed on the top line and humidity is displayed on the bottom line okay well I think that about covers it let me know in the comments if you have any questions and be sure to subscribe and like if you enjoyed it okay talk to you next time bye bye
Info
Channel: Circuit Basics
Views: 168,544
Rating: undefined out of 5
Keywords: raspberry pi, circuit projects, electronics projects, circuits, circuit basics, How to Set Up the DHT11 Humidity Sensor on the Raspberry Pi, dht11 raspberry pi, raspberry pi dht11, raspberry pi humidity, raspberry pi humidity sensor, dht11, dht11 lcd, dht11 c, dht11 python, dht11 tutorial, raspberry pi dht11 tutorial, raspberry pi humidity sensor tutorial, humidity sensor, raspberry pi temperature sensor, raspberry pi projects
Id: DPvxsHoD7kc
Channel Id: undefined
Length: 15min 4sec (904 seconds)
Published: Sat May 28 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.