Raspberry Pi DS18B20 Temperature Sensor Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you hey everyone welcome back to another circuit basics video today I'll be showing you how to set up the DS 18 B 20 temperature sensor on the Raspberry Pi the D S 18 B 20 is a small little digital sensor that looks just like a transistor the nice thing about this temperature sensor is that it only needs one wires to send data to the PI it uses what's called the one wire interface only three wires are needed in total including the power and ground wires in this video tutorial I'm going to show you how to set up the D S 18 B 20 so that it outputs temperature data to an SSH terminal like putty then I'll show you how to set it up so it outputs to an LCD display I'll be using some sample code written in Python then we'll leave a link to the post where you can copy the code in the video description alright let's get started got my PI here and a couple bread boards I'm going to put the D s 18 B 20 in the breadboard with the flat side facing me on the D s 18 B 20 the pin on the right side is VCC the center pin is the data pin and the pin on the left side is ground then I'm going to insert a 4.7 kilo ohm resistor between the VCC and data pins next I'll connect the jumper wire from the data pin of the sensor over to pin seven of the Raspberry Pi all the raspberry pi pin numbers I'll be talking about here are the physical pin numbers on the board now I'll connect the VCC pin of the sensor over to the 3.3 volt pin of the PI you can also connect it to the 5 volt pin but I'll be using the 5 volt pin for the LCD later on now connect the ground pin of the D s 18 B 22 pin 6 of the pie you okay I'm going to assume that you established an SSH connection or some other way to access the command prompt I'm going to be using putty so let me just open up putty and log into my pie here I have the full version of raspbian Jessie installed right now and the first thing we'll need to do is configure the one wire interface on the pipe to do that we need to edit the boot config file so the one way or interface will open up the next time the pipe boots up so enter sudo nano /boot forward slash config dot txt and scroll all the way down to the bottom DT overlay equals W one - gpio control X&Y to save an exit now we need to reboot to activate the boot config changes so enter sudo reboot log back in you now enter sudo modprobe w1 - GPIO then pseudo-mod probe w1 - therm enter CD four slash sis ford slash bus 4 / w one forward slash devices now answer LS to show the unique address of your D s 18 B 20 the one I have connected has the address - 8 - 0 0 0 0 0 6 6 3 7 6 9 6 now enter CD followed by the address shown in the previous step in my case I'm going to enter CD - 8 - 0 0 0 0 0 6 6 3 7 6 9 6 the D s 18 B 20 stores the temperature reading is a file called w1 underscore slave entering cat w1 underscore slave will show the contents of the file which are the right temperature of VDS 18b 20 see this number here T equals to six 187 that's the temperature in degrees Celsius without the decimal point so my sensor is currently reading twenty six point one eight seven degrees Celsius now let's run a program that will take that raw temperature value and convert it to degrees Celsius and Fahrenheit here's the blog post where you can find more details about the D s 18 B 20 techno specs she wiring diagrams steps we just did to enable the one wire interface so here's a Python program that will output temperature to the ssh determinant I'm just going to copy all this you can enter CD to get back to the root directory I'm going to create a file called temp py right click to paste the code in there I'll enter Python temp that py to run it okay so here are the temperature readings output with Celsius first and Fahrenheit second alright now let's set this up so we can get the temperature output to an LCD display I'll insert my LCD into the breadboard you now I'll connect a jumper wire from the VSS pan of the LCD to the negative rail the breadboard like the VDD pin of the LCD to the positive rail the breadboard I'll insert a 10k potentiometer to adjust the contrast then another 10k ohm potentiometer for the backlight brightness now connect a jumper wire from the vo pin and the LCD to the center pin of the contrast potentiometer then I'll connect the RS pin of the LCD over to pin 37 of the PI and all the pin numbers that I'll be talking about are referring to the location of the GPIO pins on the Raspberry Pi board next i'll connect the RW pin of the LCD over to the negative rail of the breadboard and the epen of the LCD over to pin 35 of the Raspberry Pi now I'll connect the data pins in 4-bit mode so we only need to use data pins d4 to d7 I'm going to use a ribbon cable and it's kind of hard to see but I'm connecting data pin D for the LCD to pin 33 of the PI LCD pin d5 to pin 31 of the pie six-two pin 29 of the pie and LCD pin d7 to pin 23 of the pie now I'm going to connect the jumper wire from the a pin the second-to-last pin on the LCD to the center pin of the backlight brightness potentiometer now connect the last pin of the LCD pin K to the ground rail of the breadboard you then I'll connect one of the outer pins backlight brightness potentiometer to you the positive rail of the breadboard it doesn't really matter which side you connect it only affect which direction knob turns increase or decrease the backlight brightness next I'll connect one side of the contrast potentiometer to the negative rail the breadboard same here the side you connect just determines whether clockwise or counterclockwise turns the knob turn up or down the contrast now just move the ground wire from the PI over to the negative rail the breadboard then I'll connect the negative pin of the D can be 20 to the negative rail the breadboard I'll connect the positive rail the breadboard over to the 5 volt pin to the PI pin to and the LCD lights up right away let me just adjust the brightness and contrast potentiometers you okay now that we have the LCD connected we need to install a Python library to drive the LCD it's called the RPE LCD library this library has all the functions we need to print to the LCD and do other stuff like scrolling and positioning text we need to download the library with the Python package index or pip pip might already be installed on your PI but if not enter sudo apt-get install Python - pip at the command prompt you okay now we can install the RPL CD library by entering sudo pip install RPL CD now let's open up our example program control Katie of the soon now I'll copy this example program which will output the temperature readings to the LCD you so now you can see the temperature is displayed on the LCD is the temperature in Celsius and the bottom line shows Fahrenheit and when I grabbed the sensor the temperature increases in this program we've rounded the temperature value to one digit after the decimal to change the number of significant figures edit line 31 in the code for Celsius and line 44 in the code for Fahrenheit which says round temp C comma one the one tells the program to round to one place after the decimal if we change the 1 to a 3 we get 3 significant figures after the decimal do the same for fan you so now the temperature readings are displayed with three digits after the decimal all right well that's about it hope this videos helped you get this little temperature sensor up and running on your PI if you have any questions be sure to leave a comment and if you like the video be sure to subscribe all right talk to you later thanks for watching bye bye
Info
Channel: Circuit Basics
Views: 366,747
Rating: undefined out of 5
Keywords: raspberry pi, electronics projects, circuits, circuit basics, DS18B20, raspberry pi ds18b20, raspberry pi temp sensor, raspberry pi temperature sensor, raspberry pi ds18b20 tutorial, raspberry pi temp sensor tutorial, raspberry pi ds18b20 temperature sensor tutorial, ds18b20 raspbian jessie, ds18b20 raspbian, ds18b20 jessie
Id: aEnS0-Jy2vE
Channel Id: undefined
Length: 13min 46sec (826 seconds)
Published: Sat Apr 30 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.