arduino water temperature sensor
It’S really easy to use with the Arduino and I’m going to show you how to correctly hook it up write a simple code to get it working on your computer. So you can monitor their temperature and then I’m going to show you how to control fans and motors and lights and make a little entertainment, cool entertainment center cooler that I I made up and show you how to develop that now. Here’S, the OM 35 temperature sensor it’s a basic to 92 packaged with three legs on it. They’Re pretty simple too, to use on the datasheet you’ll see that there is a this. Is your power end power out and ground now, if you do hook it up incorrectly and you get the power in and empower out wrong, you will know because it’ll get very, very hot now, for what I done on my breadboard is took the five volts from The Arduino and hooked it into one of the power rails on my breadboard took a 3.3 volt over here to this side. Then I took one of the grounds and took it to the ground, rail and then just jump to ground rails together on both sides of the breadboard. That way, I don’t have to bridge the pins coming off of the Arduino. I can just use the breadboard as for power and out to hook the lm35 up. You just want to jump the ground pin to ground the the power to five volts and the data are the out pen I’m going to put it on.
You can use any analog, pin I’m going to use analog, pin zero on the Arduino and that’s pretty much it now that we got that hooked up jump on over to the computer, and I will show you how to write the code to get this to work. All right now that we’re back at the computer go ahead and open up the Arduino IDE and get it going and start writing the code now. The first thing we need to do is to declare our variables that we’re going to be using now just to get it up and running, to tell us what the temperature is at the sensor. We only need two variables: our first one we’re going to make a float a float, data type and we’re going to call it temp see we can you can call it anything that you’d like it doesn’t have to be the same exact as mine, but you just Need to make sure you plug them in the right spots as what I do. The next one is going to be event that a type and we’re going to call it temp in and we’re going to set that equal to zero and the reason what we’re going to do. That is because the tenth sensor is plugged into analog, pin zero. So that’s why we have that variable that’s, the only two variables we’re going to need. Now we need to write the the setup function of the Arduino code, so we do void set up just like we do anytime.
We make an Arduino code. Make sure you put your code in between curly brackets and for this one I’m going to do a begin, a serial port or open up serial port and that’s just because it allows the Arduino to communicate via USB to the computer. So we can see what temperature the temperature sensor is currently reporting, and to do that we do serial dot begin. Then in parenthesis we put the rate at once. What we want to communicate with and I set mine to 9600 bulb every time and again this opens serial port communicate with the temp sensor, and it also sets the data rate to 9600 baud, and now we need to write our loop that will control what we Want the Arduino to do with the temper eat out now to write a loop in Arduino. Do it the same as we always do for a void? Loop parentheses then make sure you have your curly brackets. Everything in between the curly brackets is what’s going to execute. In the loop now this is where our variables come into play. They do temp see we’re going to make 10 C equal to analog, read temp pen and what this is doing is taking the temp pen reading and setting it equal to the temp C variable. And next we take our temp si. Instead of equal to now we’re going to write a an equation to convert what the temperature sensor is putting out to the arduino into an actual temperature that will read on the computer to do that, we do 5.
0 times whatever tipsy reading is times 100 point 0. Make sure you close the parentheses there, then you want to divide that by 1024 and again this will convert the analog input to a temperature and Celsius. Now. The next thing we want to do is take what the Arduino has converted and display it on the computer. So we can know what the temperature is, that the temperature sensor is reading to do that. We do serial dot print I’m going to do print line just so it all won’t be on the same line and we’re going to put byte in here. Just so it doesn’t want at a time, and then we want it to print out temp C, because we converted everything and stored it in the variable temp C, and this will output the converted temp to the PC. Now, after this that’s all the code that we’re going to need to read what the temperature is of the temp sensor now we want to put a delay, because if you don’t put a delay in it’s going to read it every time that sensor switches so I’m Going to put a delay in of three seconds just so it doesn’t keep going crazy. Now, when you do that, you want to hook here hook your Arduino up to the computer, let me make sure it’s connected and then you want to upload it upload. The code that we just wrote to the Arduino huh looks like I have a little bit of a spelling error.
Try this again! Okay, once you have everything uploaded to your Arduino or you can do to check and make sure it’s working is on your Arduino IDE and go to tools and open up the serial monitor and then you’ll see the temperatures start printing out now. You can also write more code that will label what’s printing out and it will print it out on a new line, so it’s not all staying on the same line. I didn’t do that because there is a graphical interface that you can get for the lm35 temperature sensor. That will allow you to see the temperature in Celsius and Fahrenheit as well as on a graph now, in order to get that you need to download the processing ID and that is kind of like a sister program for the Arduino. That allows you to make graphical interfaces for use with the Arduino development system. Now, once you have that downloaded I’ll put a link in the description of where you can find this code at but it’s it’s a code for the lm35 temperature monitor and once you copy and paste the code into the processing invite IDE, then you can just hit Run and it will open up a little graphical thing here now: it’ll keep track of the temperature on a sliding scale on a graph and tell you the readout, now I’m, not I don’t do Java programming, so I don’t really know how to do the processing programming, But it seems pretty straightforward and I’ll be once I learn it.
I’Ll be showing you guys some more about that, but you can test and see if it’s working now just hold your finger on the temperature sensor and you should see the temperature start climbing and it is rather slowly. I got my wires too closer. I can’t really grab ahold of it I’m, just touching the top of it. You can also get a lighter or something to put next to it. For a second and you’ll see it skyrocket up, take your finger off and it should start dropping back down again now. This is a pretty good little ambient temperature sensor. You can put it in a cupboard or something I’ve actually seen. People put them under the hood of their car, they’ll wire up a few of them and then run leads to them, hook them up in different parts of their car to see what the thermal dynamic. What is dynamically happening underneath the hood of their car, so they can see where problems may be arising. You can put them in entertainment, centers to keep keep an eye on the temperatures. If you have your DVD players or Xboxes or anything in them, and actually that’s I’m going to show you a little thing that I made to monitor that and cool it down when it gets too hot and now the next thing we’re going to do is I’m. Going to close out the processing ID and then I’m going to show you how to connect an indicator light for for this lm35, and what I’m going to do is set a certain temperature.
This light’s going to come on and tell me hey what, wherever this temperature sensor is it’s getting higher than the temperature that you said so I’m, letting you know and the way we’re going to do. That is we’re going to connect an LED and I’m just going to put it right on the DR dueo, put it right into pin 13 and ground, and now we need to go back to our code and we need to do a few more lines of code To get it to work, we need to create a new variable and we’re going to make this an integer and we’re going to call. It LED pin we’re going to set that equal to 13, since it’s plugged into the digital pin 13, and the reason I use 13 is because you don’t need a resistor or anything when you, when you run an LED with pin 13, because it already has a Resistor in line with that pin now so the comment I’m going to put on this code is that the LED is connected to pin 13. Then we need to go on down and how we’re going to get this to turn on with whenever the temperature reaches a certain point, is we’re going to do it with an if statement so we’re going to say if temp C is greater than 25, you can Set that temperature to anything that you want put that in curly brackets everything that’s in the curly brackets will execute FDF statement evaluates to true and what we’re going to do if the temperature gets above 25 degrees Celsius is we’re going to set we’re going to digital Right led pen we’re, going to write that hi now with you.
Don’T have to do an else statement. I do it just just because something that my teachers taught me to do all the time it’s not necessary, but if the temperature is not over 25, what we’re going to do! We’Re going to digital right, the LED, pin we’re going to write that low this time. So what this is going to do is if the temp, if temp C, is higher than 25 it’s going to turn the light on if it’s lower than 25 it’s going to keep the light turned off now, once we do that upload it to the Arduino as Long as you don’t have any errors in your code seems like I’ve, been having a lot of errors today, and once you get it written to your code, you can try it out. Put your fingers over your temperature sensor raise the temp up and whenever it gets above 25, it will turn the light on, and one thing that I forgot to do is we did not set the pin 13 up as an output, so we got to go back To void setup and write pen mode, then we’re going to do the led, pin we’re going to set that to output and how I notice that this I forgot to put this in is the LED would turn on, but very slightly so now that we’ve set the That pin 13 has an output, we can re upload it again and then we can try it out and once it’s done, uploading wrap your fingers around your sensor, heat it up and the light comes on and it should go off whenever the temperature gets back down To 25 now we’re going to take this one step farther now.
In order to do this, we are going to use a fan. I got just a simple little. Computer fan that I’m going to use and I’m going to get off the computer go back to the webcam, show you guys how to hook it up and then I’ll come back to show you how to program it in alright. Now, what we have here is just a regular little 92 millimeter PC fan come out of an old PC case. You know what I’ve done is strip the ends of the wire and we’re, going to hook it up to the Arduino and the way we’re going to do that. We’Re going to hook the ground straight into the ground rail on the Arduino. I can get the ends to keep from fraying hook it right into the ground rail of the breadboard that we’re going to take the power we’re going to hook it into digital pin I’m going to choose, pin five. Now this is a 12 volt fan, but it will run at 5 volts. It won’t run very hard at 5 volts, but it will run and the reason I’m going to do this is to show you that you can use the digital, pins and I’ll. Show you how to run it off of a 9 volt battery in just a second now to get this running, we got to go back to the computer and I will show you how to write the code to get this to work all right now that we’re Back at the computer we’re going to get the fan the code written for the fan so that it will turn on when the light turns on and turn off when the light turns off now.
In order to do that, we need to declare another variable we’re going to make that a type int also we’re, going to call it fan 1 or anything else. You want to call it we’re going to set it equal to 5, because that is what pin that the fan is connected to on the Arduino and I’m we’re going to comment that to say fan, one is connected to pin five just so we know if we Have any problems later now learn from our mistakes and then the setup part of our code we’re, going to set the pen mode for pen 5, which is fan 1 we’re, going to set it as an output? Just like we did the led we’re going to go down to the loop and right below where we set the LED higher low we’re going to digital right we’re, going to write the fan 1 hi they’re going to go right down to the else statement and write. It too low if temperature is below our 25 degrees or below so pretty much the same thing that we did with the led we’re doing with the fan I’m going to upload that then we’re going to jump back over the webcam and make sure it works. Now, just so, I stay out of your guys’s way and you can see a little bit better I’m going to be using my hot air gun from my soldering station to heat up the temperature sensor to see if it turns on the fan and the LED like We want it to the fan and the LED come on and make sure that they shut off, and this fan is not blowing out too much air right at the moment, because we only have it running on five volts and that’s.
Not what it was designed to do now, the LED shut off and the fan shut off so that part’s good, now I’m, going to show you how to hook up the fan and control with the Arduino using a 9 volt battery. Or if you have a boost. Converter or step up converter that can go from 5 volts to 12 volts to run the fan with that be great right now. Only thing I have is a 9 volt battery so I’m, going to show you how to connect that with transistor and I’ll be back in just a second now to get this running on 9 volts, instead of 5 volts we’re going to use a simple NPN transistor. This is a 2n ’04 transistor and it has 3 legs also. It has a an emitter, a collector and a base, and how we’re going to hook this up is we’re going to for the base we’re going to jump over and use, pin five, just like we did before we’re going to set that to the base of the Transistor, which is the middle, pin now we’re going to take the negative part of our fan, we’re going to put it in the collector of the transistor two collector pin. Then the emitter pin we’re going to connect a jumper from the emitter over to ground and what that will do is whenever a signal is given out from the Arduino to turn the fan on. It will flip the switch in the transistor and a lock connection between the ground wires to complete the circuit.
Now we’ll put our power on over here for the fan and then we’ll get this simple: 9 volt battery adapter and we’ll hook the power end of it and the same with the power from the fan. It will take the ground for it straight to ground. Let me get our 9 volt battery and connect it up to our adapter and now, which our fans should run at nine volts instead of 12 volts, and we will see if this is true right now get my hot air gun, try to heat it up again. It comes on and it does and it blows out much more air than it did from running it on the Arduino that’s, just a simple way: to use a battery to get the Arduino to control a fan is by using a transistor now to take this circuit. One step further and complete our entertainment cooler. What I’m going to do is I’m going to hook up a servo motor because, right now we have the temperature sensor that will allow us to detect when our entertainment system gets too hot. We have an LED that will turn on to tell us hey your systems too hot. You need to do something about it. Now we have a fan hooked up that will circulate air through the entertainment system to cool it off now that fan is going to be starved of air if it’s just trying to pull air out or push it in and there’s nowhere for it to go.
So what we need to do is a way to open a door or we can put a hole beside the fan or opposite the fan that will allow air to push through. But the way I designed it is to use a servo motor right here and what it’s going to do is it will swing out to the side and prop the door open, just a crack to allow the for sufficient airflow through the system whenever it gets too Hot and how we’re going to hook this up is put it in the black pen goes to ground. The red pin goes to five volts, plus five volts and then the sensor wire data wire, the yellow pen, will go to whatever and we decide to use and for me, I’m, going to use pen three I’m using pen three because it’s a PWM pen and now We need to go write some more code to control the servo motor and jump back to the computer. Show you how to write the code for that and then we’ll be done. Alright, now that we’re back to the computer, we need to write the code to control the servo motor as well, and this is going to get a little bit different than what we’ve been doing before, because the Arduino does not come preset with a circle library. And you should, if you watch my photocell tutorial, you will pretty much know how to do this already. But first we need to include the servo library.
So we do pound include, we use in inside care brackets lead right, servo, dot, H and that lets the Arduino environment know to include the servo library several header file. Now we need to create a servo object. That way, the ID will allow us to control the servo motor with code. So a way we do that is we write servo. Then we give it a name and the way I’m going to do it I’m, going to call it servo. 1. All right! We go on down, we have to create another variable, and the variable we’re going to create is for the position of the servo, not for the servo itself. We already declared an object for the servo, so we don’t need a variable for that, but what we do need is a variable for the position and I’m going to make this type int or call it POS for position where I set it equal to zero. Now, in our setup function we need to attach our servo to the Arduino way we do that is very servo dot attached. Then we tell it what pin we want to attach it to and we attach it to pin actually mines, pin three and go on down to our loop on our loop. What we’re going to do is in the if statement we are going to set the POS, and this is the if statement. So if the temperature gets above 25, we need it to do something right now.
We have it turning the fan and the LED on and we wanted to control the servo as well, but in order to control the servo, we need to change the value that the variable position is storing and how we do. That is. We write POS equals 180 and that means if the temperature is greater than 25, then POS is going to equal 180 and we go on down and we’re going to do. Servo 1 dot right we’re, going to tell it to write the position and since we set position equal to 180 it’s going to turn the when it writes the position to the servo it’s going to write 180 degrees. So it’s going to turn the arm to 180 degrees and then the else statement we do the same thing. We write POS equals 0, that we do servo 1 dot right we’re, going to have it right POS again and in this case POS is going to be 0, so it’s going to turn back to 0 degrees. Next, I don’t want mine to go full rotation. So I’m, going to put it as 90 degrees just to minimize the amount of movement. Now that looks all good as long as we don’t have any errors in our code, then we can upload it and look at that got another error. I would get that done and head on over to the webcam and see if it works all right now, we’re back at the computer or at the webcam and we’re going to test to see if our servo motor moves every time that you’re making a project like This and you write new things in your code.
You need to test it each time you do something that way. You know where the code is going wrong at now. We tested it after we put the led in test it after we put the fan in now, we’re doing the servo I’m going to get my hot air gun heat it back up again and make sure everything’s working in harmony, servo motor went open now holding the Door, open fan, turned on and light turned on. The list know that it’s too hot. We need to keep an eye on it now, once it gets back to a safe temperature, the motor will go back to 90 degrees. Now the door to shut the fan will turn off and the LED will turn off. As you can see, this is a something that I created to protect my PlayStation and Xbox, while it’s in the entertainment center to keep them from overheating. Now I am eventually going to create a boost. Converter I’m waiting for the chip now it’s in the mail. Then I’m going to put it on a proto board with a an Arduino mini. That way, I can put everything inside the cabinet without having to give up my uno and it will run I’m going to run it off of wall power instead of instead of battery. That is a pretty good little circuit to have. The purpose of today was to show you how to hook up the lm35 sensor, how to read from it and show you all the different kinds of things you could do with the temperature sensor now.
The lm35 only does temperature it doesn’t do humidity or nothing but it’s a it’s. A really good, accurate sensor really easy to interface with the arduino, and you can do a lot of cool little nifty projects with it that’s going to be all for today. If you could rate comment subscribe and I’ll keep making these kind of videos for you guys stay tuned for some more unboxings. I got a couple more reviews coming out this week and I have another Arduino tutorial on the ping sensor.
arduino water temperature sensor Video
arduino water temperature sensor news
Posted on Tuesday February 26, 2019The No-Parts Temperature Sensor In Your Arduino Hackaday[Edward], creator of the Cave Pearl project, an underwater data logger, needed a way to measure temperature with a microcontroller. Normally, this problem is … … Continue Reading »
PT100 Resistance Temperature Detector (RTD) Probes Support Extreme Temperature Ranges – CNX Software
Posted on Monday September 02, 2019PT100 Resistance Temperature Detector (RTD) Probes Support Extreme Temperature Ranges CNX SoftwarePT100 temperature probes are more accurate, reliable and support much larger temperature range than traditional thermocouplers. … Continue Reading »
Posted on Sunday July 21, 2019An Epic Tale Of Thermistors: Tricks For Much Better Temperature Sensing HackadayFor years [Edward] has been building professional grade underwater sensing nodes at prices approachable for an interested individual without a government … … Continue Reading »
arduino water temperature sensor Social