How To Interface DHT 11 With Raspberry Pi | Temperature Measurement

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello in this video Let's see an actual sensor in action with Raspberry Pi for this particular video we have chosen this sensor which is called as dht11 to interface with Raspberry Pi there are several reasons for choosing dht11 the very first reason is it's very simple digital sensor and therefore it can directly get interfaced with Raspberry Pi the second reason for choosing this one is it gives us two values those are humidity as well as temperature so it can sense the atmospheric humidity as well as temperature and it can give us those two values the third important reason for choosing dht11 is its price almost anyone would be able to afford it because dht11 comes very cheaper now let's see how we can interface vht11 with Raspberry Pi and how we can write down a Python program for the same a little bit about dht11 as said it's a digital temperature and humidity sensor this contains a negative temperature coefficient thermistor for measuring the temperature value and it consists of a resistive type humidity sensor so both the temperature and humidity are sensed By changes in the resistance Itself by the elements which are present inside the sensor but the sensor also consists of all the required Circle battery which is required to process these values coming from the sensor and therefore what we get is a complete Digital Data onto a single wire it requires only single wire or one wire for data signal and therefore it is easier it is very easier to interface dht11 with a variety of different controllers any controller or any microcontroller like Arduino or any computer like Raspberry Pi can be easily interfaced with dht11 [Music] operates on three to five volt power as well as input output pin so it is okay if you operate it or 3.3 volt while using with Raspberry Pi and 5 volt while using it Arduino the maximum current it requires is quite low it is 2.5 Milli ampere for that to only during the conversion and the humidity readings are good between 20 to 80 percent with five percent accuracy the temperature readings are good up to 50 degree celsius and the tolerance is plus minus 2 degree Celsius the sampling rate it means the data rate with which it can pass on the data should not be more than one Hertz means it cannot give data more than once every second the body size is specified a bit and it also specifies it has got four pins although we need only one pin for interfacing and two pin for power correction one redundant or NC pin is there which is not to be connected anywhere let's see the pin out so this is the pin out of dht11 now in this particular pin out as you can see the pin number one or the first pin from left hand side is VCC which should go to 5 Volt or 3.3 volt in our case it will go to 3.3 volt because we are interfacing it with Raspberry Pi so this is the PIN number one which will go to 3.3 volt the second pin is data pin third pin is NC and the fourth pin is ground or zero volt pin this is how we have to give connections so this one will go to 3.3 volts this is data pin which should go to any GPI pin of our Raspberry Pi and the last pin is ground moreover there is one thing required and that is this pull up resistor this is something very important and you simply cannot miss this you have to connect an external 10 kilo ohm pull up resistor between VCC and data pin so it will be something like this you can connect it on a breadboard while interfacing so that's how the interfacing of dht11 is to be done with Raspberry Pi let's see the library installation for dht11 how to install the library required and how to write down a sample program now before installing any libraries from GitHub GitHub I will discuss in detail in a later video it's an online repository where the the software codes can be saved and easily downloaded and we do make use of the Adafruit made libraries Adafruit is a very popular company making DIY kits which is situated in New York USA and they also create lot of different libraries for Raspberry Pi to make things easier to handle the sensors like dht11 now now so let me show you what are the commands that we need to run and how to install the library the very first command is this entire thing git clone https github.com adafrote slash Adafruit underscore python underscore dht.kit the underscores are not seen here because it is treated as a link let me show you if I remove the hyperlink you can see the underscores are there this is the first command what will happen with this command is you download the software onto the Raspberry Pi so this will simply download the code the job of this is download code second what we do is it downloads the code in a folder okay so it downloads the code folder that's the first commands to execute the second command to execute is this it means we go inside the downloaded folder with this particular command the third command is installation of some Essentials which are required to install python libraries so sudo apitigate installed build essential python Dev is already there python open SSL is required so you can run this command depending upon if the packages are available or installed or not it will require those ones which are not installed and then the last command which you can see is installation of python libraries now this particular command here is pseudo python and therefore what I have done is I have given you additional instruction where you can also directly install it for Python 3 with sudo pip3 install Adafruit python DHT so either this or this approach is suitable so all these above steps or this single step below okay the fifth step are all the above steps and when you are doing it for Python 3 instead of making it pseudo python make it python3setup.pi installed let me show you now let's do it on Raspberry Pi itself so what I'll do is I'll follow these commands first download the code then go inside it and build it on my Raspberry Pi so let's copy this command Raspberry Pi it's close whatever it was open over there full screen clear ones now I'll paste it and it will download the Adafruit underscore python underscore DHT now I can open the home folder and you can see the folder being created Adafruit underscore python underscore DHT now let's go inside that folder CD Adafruit underscore python underscore DHT at this point we have to install some important or required dependencies by this command sudo apt get installed build essential all in all so let's copy this and enter so those packages as required are installed unable to locate python python open SSL so let's remove the python-trave let's keep only python open SSL so they are already installed no need to do anything over there now let's run the last command which is sudo python setup dot Pi install sudo python three I will use setup dot Pi space installed because we are installing the libraries for Python 3 and Raspberry Pi by default contains both python 2 as well as Python 3. and whenever you refer to something as just python it is oftentimes referred to python 2. and hence if you have to specify Python 3 better you simply write down sudo Python 3 like this now it will run the libraries it will install the libraries onto Raspberry Pi which we have just downloaded now the library installation is done next what you have to do is go to Adafruit underscore python DHT folder you will see the examples folder over there and here you will see this simple test dot pi so simply copy this simple test dot pi keep it somewhere so what I'll do is I'll create a folder over here course codes I'll just paste it here simple test dot pi I will rename it so that it reads DHT underscore simple test dot pi now it's time to perform the connections with Raspberry Pi and see the output of this program let's see the corrections and let's then try to see the output of this code in the next video thank you for watching this one now as you can see I have a DHT one module over here so there isn't much change in what I showed you and this module the only change is the required pull-up resistor is present onto this PCB along with a power on indication LED and therefore it has got only three pins as you can read VCC data and ground so if you have a module like this you can directly interface VCC pin here data pin here and ground pin rights over here otherwise you can install the dht11 sensor in the breadboard and then perform the corrections as you want for me since I have this module I don't want to use the breadboard now I can simply use female to female character and directly connect it to Raspberry Pi now I'll just keep this setup aside this is the LDL setup we did now you can see this is the female to female bias okay both hands are female connectors as you can see now I've connected like this all three pins you can see the white is VCC and the brown is ground the Blackness data so the white is VCC in brown is crunch so this is the ACC connection that I am making the third pin from the left first pin from left side is VCC the third pin from right side is ground after this connection I can see the LED power down over here and this is the beta page which I correct to the identify pin pin number 21. now the connections are done for this particular sensor now let's see the output let's keep it as it is now let's open this DHT underscore simple test dot Pi in thony ide it's a simple testing code guides so I'll first demonstrate this and then we'll try to do something out of this test code it has got a lot of comments into this code first there is Declaration of sensor so we are not using dht22 we are using DHT one one so just make a dht11 and let me clarify the code a bit so that you understand it well and don't think that it's quite big or quite heavy so first Declaration of the sensor if you can if you want you can use dht22 also which is a bit accurate than dht11 but expensive if it is CSU 2 2 just make it 2 2 otherwise make it one one connections and everything remains almost same then here we mentioned the pin right now we have connected it to 21 number of Raspberry Pi so let's make it 21 and now these are the lines so temperature humidity comma temperature is equal to Adafruit underscore DHT dot read retry is because in single reading you may not create the dht11 response and therefore you want to retry it this particular line over here will wait for two seconds and it will retry it for 2 seconds if there is no data then an error will be displayed after the data is received on the next line what we do is we are checking if humidity is not none and temperature is not null it means we have got some Fair valid values for temperature and humidity and in that case what we do is I will remove these complications and make it simple and then what we'll do is we'll print temp is equal to the first parameter and the humidity is equal to Second parameter so temp is equal to bracket 0 humidity is equal to curly bracket one dot format temperature comma humidity else fail to get the reading try again it means if either of these two value is none or zero it will fail to get the reading and try again now let's run this code the connections are done we are supposed to get a reading over here or the temperature of humidity value over here as you can see we got the temperature and humidity value so temp is equal to 28 degree celsius and humidity is equal to 47 percent but the program exited by giving a single reading now what I want is I would like to convert this program intro code which can give continuous values let's switch to the regular mode of funny by closing it and restarting it again [Music] this is the full mode in which you can save the programs as needed so I'll go to file and I will call it same ads and then DHT instead of simple test let's called continuous test let's shorten the code now you have got a fair idea of how it's working now what I want is the code should run in infinite Loop so I will also import time Library and from this point on onwards my program should be running in while true Loop so that it gives us continuous readings after you write down while true and the curly press the colon is opened you need to indent your program like this foreign like this similarly for else now this is done once after single iteration what should we do is we'll take a delay of let's say one second and now let's run this code now let's see the output over here so we are getting the readings temperature is equal to 27 degree celsius humidity is equal to 48 point something 49.0 also happen to have a soldering gun over here so this is the soldering iron that I have and I can keep it close to this dht11 so that it can sense some of the temperature that it's giving so the soldering gun is turned on it has started heating up but uh will take some time now let's try to see so the well is quite hot now now let's keep it close and blow some air through it so it is sensing the atmospheric temperature and therefore not much change would be observed still you can see the temperature is risen by one degree Celsius in proximity to the gun I have a more experiment which we can do here instead of the soldering gun now I'll use the hot air gun how much decoration it can sense well now this is the hardware gun that I have let me show you so these are the settings for it so I'll just make it on now this is the air and this is temperature setting so let's keep the temperature on the mid setting air normal should not be very too much higher flow otherwise the sensor would get damaged make sure if you are doing this kind of experiments then keep a distance between the nozzle and your hand as well as the nozzle and the sensor also so this is the nozzle and this is this is I'll keep it quite far away from each other but hot air is blown code has stopped let's stop it and let's run it again so you can see 31 degree Celsius then foreign hot air into it 47 49 don't do it more than that otherwise you might damage the sensor now let's keep the gun that let's close the airflow let me remove this setup and now observe the readings slowly they will come back to the normal position 47 46 and so on should take some time but after some time it will come to normal point so this is the code that you need to run or to read the temperature from dht11 sensor we have seen the dht11 sensor in action as well as we have seen it extensively tested with a hot air gun also make sure whenever you perform this kind of experiments you maintain proper safety thank you for watching this video
Info
Channel: Kitflix
Views: 13,280
Rating: undefined out of 5
Keywords:
Id: WUoCCQmxxEk
Channel Id: undefined
Length: 20min 14sec (1214 seconds)
Published: Fri Jun 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.