Placeholder Image

Subtitles section Play video

  • Please go to the line, the computer guy dot com and failed normal dot com to see the videos that are too dangerous for YouTube.

  • Welcome back.

  • So in today's video, we're going to use in our we know, you know, with WiFi board and an analog temperature sensor to create a temperature sensor that is accessible through a Web browser.

  • So let's say you want to create a temperature sensor.

  • You want to be able to see what the temperature is in a server room in your basement.

  • Just basically, you want an Internet accessible temperature sensor.

  • The project today will allow you to do that.

  • So we're basically going to combine these two were that's gonna take an analog temperature sensor.

  • We're gonna take the Arduino who know.

  • Bored with WiFi, we're going to add a little bit of code, and then we're going be able to access this board from a state of dirt i p for Internet address on.

  • Then we will be able to see what the temperature is from a Web browser, whether it's safari or Internet Explorer or chrome or whatever else, so that let's go to work meant to show you the components and how to build this project.

  • Then we'll show you the code and how it works.

  • So you don't need a whole lot for this particular project.

  • We have the art.

  • We know who.

  • No WiFi board.

  • We have our analog temperature sensor.

  • We have our bread board and we have a couple of jumper wires.

  • That is all we're going to need for this particular project.

  • Simply slot the analog temperature sensor into the bread board again.

  • When you're looking at the analog temperature sensor, the left side is positive.

  • The right side is ground and the center is the sensor pin.

  • Do you make sure you get this correct or you will burn out your temperature sensor.

  • That's why should always buy or we know components by the dozen.

  • Then we're gonna do is just simply gonna plug ground on the ground.

  • We're gonna plug positive and 35 volts, And then for this big project, we're going to plug the sensor pen into a zero because that's what we have in the coat.

  • Now, one thing for this project just so you know, is I did actually have to pull out my multi meter who had to pull out some of those old electronic repair technician skills because when I did this project and we were reading the temperature sensor from the sensor, the temperature was about five degrees warmer than it should be.

  • And so I had to go through in trouble.

  • Shoot.

  • Why, that is, and what I found the problem to be is this particular board.

  • I don't know if it's this particular board, as in this specific one, where it may be something with the WiFi boards in general.

  • But when I connect to the five volt power pin on this artery, no board, I only get about 4.85 volts.

  • So when I take my standard Arduino board and I connect to the five old power pen, I get 4.997 bolts so close enough to five volts a cz faras.

  • Our projects are concerned with this particular board.

  • We actually don't get a full five volts again.

  • We got like what I read was about 4.85 volts.

  • And because of that, remember all the temperature readings and everything is based off a voltage.

  • So if we're not getting the full amount of voltage at the 50 then the readings that we get back will be different than what they should be.

  • And then the temperature will be different than it should be because all the timber cure is based off of the voltage being put through an equation.

  • So this is just something to keep in mind, especially if you're going to be doing my five based projects on especially you're gonna have multiple of these projects is make sure to calibrate your your board and your sensor and your project to make sure it's giving the readings that it's supposed to.

  • So in this particular case, since this project gives me temperature, that's about five degrees somewhere between 4 to 5 degrees higher than it should be.

  • I might simply go in.

  • And what I create the temperature Fahrenheit variable.

  • I may simply subtract five from that in order to get that variable.

  • And so this is something that you should be thinking about it for some reason, you're knocking the proper voltages or things are coming through to give you the exact number that you're supposed to be getting.

  • You should be thinking about when you're doing dealing with a sketch.

  • Should you add five years, should you subtract five there, so so on and so forth?

  • But that's just something to keep in mind.

  • I'm not sure if it's the board in general, as an all boards would be this way or this specific board.

  • But this specific board on the five ball pit is only giving out 4.85 or so volts, which causes does cause an issue for the actual reading for the temperature sensor.

  • Other than that, it's simply shows us a temperature that's about five degrees warmer than it should be.

  • Otherwise, everything works how it should.

  • So this is just something to keep in mind.

  • Now, with this again, if you're gonna be powering this, do you remember?

  • Since it's gonna be WiFi And since you're gonna be accessing over the WiFi, you can take something like a USB pat battery pack.

  • Or you could use an external power adapter to power this particular project.

  • So again, that's one thing I realized when this kind of project here So you could have this completely separated from any kind of computer, and you can still access it over your wireless network because it has that WiFi component.

  • So with that, let's go over to the sketch to show you how to code for this thing.

  • So here's a sketch for this project.

  • And like many of our projects, I'm basically just combined two projects we've previously done.

  • So I have come by the basic Arduino, you know, with WiFi board set up a video that we did previously and I've combined are analog temperature sensor projects that we've done previously.

  • So with this, in order to be for this thing to be able to communicate over the WiFi we're going to do you include to libraries.

  • So we're going to include the SP I got H library and the wife I nine a library.

  • So the first thing we're gonna do is include those libraries past that we're going to have to define the sensor pen.

  • So where is the data gonna be coming from?

  • From that temple analog temperature sensor pen.

  • And so we're going to define.

  • We're going to call it sensor pen, and we're going to connect it to analog zero a zero.

  • Then we're gonna come down.

  • We're going to give the information that's required in order to connect to our WiFi network.

  • So Char s s i d equals.

  • And so I have a guest network that I've simply called test pr past.

  • So this will be the password for your WiFi network.

  • I have left it blank just to make my life easier.

  • And then it end Key index.

  • If you're using WiFi network with multiple keys, this is where you would give the number for for the key index that you're using.

  • Since we're not using any passwords, that doesn't matter for us.

  • The next thing that we're gonna do is we're creating end status variable, and we set the value to that to W el I an old status.

  • So this just simply says we're creating a status for our wireless network, and we're starting up with it being idle.

  • Then we're going to do the WiFi server, and we're going to set the server to poured 80.

  • So if you wanted to use a different port for some reason, you could set that here.

  • We're using poor 80 because that was just simply to stand or http port.

  • So that's the first component of the sketch that you're going to have to type out, then passed that the first thing that we're going to do is cereal dot begin 9600.

  • So this starts the serial monitor so we can see it.

  • What is going on with the Arduino board, then?

  • The next thing that we're going to do is we are actually going to try to connect to the WiFi network.

  • So there's a wild we'll loop.

  • Wild status is not equal to wireless link connected.

  • So while it's not connected to your old ah print attempting to connect so so simply print out the serial monitor Year old opera S s I d.

  • So this will print out the s s i d.

  • So I will print out test, then status equals y fi dot begin s s I d password.

  • So this is the function that actually tries to connect you to the WiFi network so it will feed it the s s I d.

  • And the password.

  • And if that works, you should connect on in this.

  • Delays forward 10,000 milliseconds or 10 seconds because it's a while loop.

  • And you don't wanna be hammering WiFi network to heart once Once you break out of that, that wild loop.

  • So once the status is connected, then you're gonna break out, and then you're gonna do server, not begin.

  • So that starts the server service on the Arduino.

  • Who?

  • No WiFi board.

  • At that point, we're going to print out to the serial monitor basically to say we're connected it to the to the network.

  • We're going to print out S s I d.

  • Then we'll print out what the s s i d is.

  • We're going to set a variable for the I P address, which is the wife I'd out local p.

  • Then we got a serial print i P address, and then we'll print out the value of the I P.

  • Address.

  • This is very important here because again, unless you hard to code the i p address for your little Arduino device, you need to know what the hell the I P addresses.

  • We're gonna go to an I P address.

  • You need to know what it is.

  • So we either need a hard knock over the I p address in the art we know device or you need some way to be a hotel.

  • Tell yourself that.

  • So whether it's an LCD screen that prints it out or whether you printed on a serial monitor you need some way to know what the hell the i.

  • P address is of your own, then passed that were just simply gonna go down and we're gonna go into the loop.

  • And again, this is where we cut and paste sketch is previous sketches that we've done.

  • The first thing that we need is Thea the way that we're able to gather or collect the actual temperature sensors s O.

  • This is the analog temperature algorithms and self that we normally d'oh.

  • So we dont have a variable and reading equals analog, Reed said.

  • This reads from a sensor pits and this is where I'm telling you, for this particular board, this reading is wrong.

  • Well, it's not that that readings wrong the readings right, But because of the voltage, it's not what occurs, what's supposed to be.

  • And so this is where again, like, say, in this math, you may want to go in and plus or minus or something in here.

  • If you need to tweak this, then we create the voltage way divide able to derive 1024 then said it then we have a float for temperature.

  • See?

  • So this gives us the what the temperature in Celsius is in order to get the temperature of Fahrenheit.

  • We have this here.

  • And so basically all this does here is you copy and paste this and this gives you the temperature so you can print out that value.

  • Then we come down here and this is the WiFi connection.

  • So this is how we actually send data to the Web browser that is connecting to the Arduino again.

  • Remember, in the technology world, you actually have to you explain how all this works in this code.

  • Here is what does that So WiFi client equal server available says makes a server available if there is a client print line.

  • So there's a cereal print line so this will print in a serial monitor.

  • New client.

  • Then we have a string.

  • Current line equals basically nothing Wild client is connected.

  • If client is available, Char character C equals client read.

  • And so what?

  • What's gonna happen here is basically it's going good.

  • So So when your Web browser connects to the Arduino, your Web browser actually sends the artery no information.

  • So what the Arduino has got to do is it's going to parse that information literally character by character, because it needs to know when descend information back to your browser.

  • So it's going to pars character by character.

  • And what's gonna happen is when it detects a new line that is black.

  • So basically, when it connected finds a new line.

  • And if the current line length equals Blank s, Oh, there's nothing there, then is going to print out to the client.

  • So basically, what is doing this is parsing character by character, by character, by character, he comes to a new line, and then if the new line is blank, then it sends information to the client.

  • If the new line has information that it keeps waiting, waiting, waiting, and then the rest of this down here is part of that function.

  • So the main thing that we're worried about is this little section right in here.

  • So if you get if it gets to a new line and the new line is blank and then it's able to send something to the Web browser, so client dot print.

  • So we're going to print to the client client dot print.

  • We're going to print out temperature colon space, and then client, not print line is temperature F.

  • So to be clear, here, all I'm doing is printing now in basic asking text.

  • So again, since we're printing to a Web browser, somebody think about is you can format with H came out.

  • I could form at this with H one tags and bolds or Strong's or colors or other things with this.

  • Since this is a simple project, all I want to show you is that it can print out text and the value of variable, and that will show you what the temperature the analog sensor is reading.

  • So that's why we're doing this year again.