DS18B20 Temp Sensor Raspberry Pi Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys welcome to my first special request video i got a comment on one of my previous videos asking me to do a tutorial for the ds18b20 temperature sensor now this is a really cool sensor because it uses a one wire protocol and what that means is you can hook lots of different devices up to only a single data wire and by use of addressing the different sensors it can isolate each one and read from each one individually it's kind of like i squared c addresses but uh it's it's a little different it only uses one data cable and that's pretty cool so all you have to do is surprise supply voltage uh that's it aside from the data cable but you can use three to 5.5 volts to power this sensor i've always had better luck with five point or five volts every once in a while when i use 3.3 i can't read from a couple devices i don't know why it might be my mistake but uh i'm using 5.5 volts if you'd rather use 3.3 feel free it should work just fine but without further ado let's hook this thing up so this one i've already hooked up a couple dupont cables to there's also a through-hole sensor that is not wired up like this this is just the waterproof housing for it with a long cable but i soldered two different kinds here so i just kind of had to adapt it but this is your data cable on the yellow one and this is your voltage and ground right here so i'm just going to plug voltage and ground in right here data i'm just going to put on this top rail right there and then we need to bring data over to physical pin 7 on the raspberry pi that's gpio4 and it is the only pin on the raspberry pi that can use the one wire protocol so be sure you hook it up to the right pin that's the fourth one down on the left side here again just look at the pin out it's physical pin 7 gpio4 so you go one two three four easy to remember because it's four four um and then i grab the wrong jumper here let me grab a different one okay let's see here oh that's the wrong bit okay that'll work okay now we're going to hook up our power and ground to i'm using five volts so it's one of these top two on the right and then the third down on the right for ground and then we need our pull up resistor from data to voltage so i'm plugging in this into this top rail here and bridging that over to voltage and that's all there is to it as far as the wiring it's really simple like i said you just supply voltage and then the data cable and this is basically just going straight from here to gpio4 on the raspberry pi with a pull-up resistor from the data cable to voltage so that's all there is for the wiring i'm going to go ahead and plug this into power and log into the raspberry pi headlessly for my computer if you are not sure how to do that i will link a video in the description on how to get your raspberry pi going headlessly so you can just log in from your desktop and program it from there or if you have a screen and keyboard hooked up to your raspberry pi that'll work just as good so i'm just going to plug this in this should light up there we go now we're cooking all right let's go over to the computer all right so before we can uh connect to the one wire sensor we need to do two things one is go to sudo raspy config go down to interfacing options look at one wire hit enter would you like it to be enabled yes okay arrow over to finish and then it will ask you to reboot do that and come back to this screen once you get back to this screen what you're also going to need to do is type in sudo nano boot config dot txt and this is editing a boot file uh you come all the way down to the bottom and uh dt overlay equals w1-gpio should already be there if you've enabled one wire if it isn't go ahead and type this in but you will need to add comma gpio pin equals four once you've typed that in hit control x and it'll ask you if you want to save it i already did that so it didn't ask me to save but just hit y and press enter okay so next you're going to see a few things pop up on my command line because i'm kind of figuring this out as i go i used to do it a little differently but this is a much simpler method so uh just follow along in the order i have everything in the video and you should be good to go what we're going to do first is we need to import the library that we're going to use to read the sensor that is sudo pip 3 install w1 therm sensor and i'm going to wait for that to install mine's already installed so it'll probably just say condition already satisfied but on yours it should go through the installation process yep requirement already satisfied okay so yours will go through installation process it'll only take a few seconds um but now we're going to use nano and create a script that runs uh it will read the temperature about once every second and display it so we're going to import time and then we're going to go from w1 w1 therm sensor import w1 therm send sir and then create sensor as an object sensor equals w1 therm sensor open close then we're going to make an infinite loop by saying while true temp equals sensor dot get temperature print temp and then time sleep one second then hit control x save modified buffer yes name to right or i'm just gonna save it as therm sense thermsense.pi be sure to say add that extension on there thermsense.pi and then we're going to say ls and we see thermsense over here uh 1w sensor was another one i made while i was debugging it but thermsense is the one we just made so we're going to say python3 therm sense and so if i could spell dot pi and that should display the temperature there you go it's 21 degrees in my office and now let's just make sure it's working i'm going to hold on to the sensor and it should start going up in temperature yeah there we go and that's how to connect a ds-18b 20 maxim integrated one wire temperature sensor now let go it should start going down here in a second yep there you go so it is reading the temperature and that's how you do it all right guys well there you have it that's how to use a ds18 b20 sensor with the raspberry pi um i can't think of anything else to say about it but if you have any questions please comment i see all the comments um so i will do my best to help you out if you run into any problems but i guess that's all i've got for you so if you found this video helpful please like subscribe if you want to see more and all as always be sure to be kind to someone today peace
Info
Channel: Maker Jake
Views: 12,115
Rating: undefined out of 5
Keywords: diy, electronics, project
Id: wDdJ6stXQi0
Channel Id: undefined
Length: 9min 59sec (599 seconds)
Published: Mon Apr 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.