Placeholder Image

字幕列表 影片播放

  • 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.

  • We could have HTML Tex and all kinds of other stuff here or tags, but I'm just doing this to be simple.

  • Then we go through, we finish, we finish the rest of that, that part of the else.

  • Then we do.

  • Clients stop.

  • So once we've printed to the client, we actually need to stop that connection that we do cereal that print lines were printing a serial monitor client disconnected s O.

  • That.

  • Then we connect this to we connect aren't we know?

  • Board, uh, to to this we upload the sketch and then we should be able to read what the temperature is from the web browser.

  • So here I am, connecting the lottery.

  • No project to the computer.

  • So this will give it power and will be able to upload our sketch.

  • I'll simply upload our sketch again.

  • When you're doing this.

  • Do you make sure to go tools aboard and make sure you've selected the right board?

  • So this is the artery?

  • No, no WiFi rev too again, If you're using multiple boards, it's very easy to stay on the yard.

  • We know, you know, when you try to upload and will fail, so do you.

  • Make sure you select the right board, then once has been uploaded, we could go to tools, you go to serial monitor.

  • And then this is where we have attempting to connect to a network name the S s I D.

  • So it's a test Should take about 10 seconds for this Thio too.

  • Be connected to the network and then we have yet.

  • So we have our s s I d equals test and we have our I p address 1 72 16 42 5 is What we can do is we can take that I p address.

  • We can go to our Web browser, and so I already have this plugged in.

  • We can hit, refresh and who Look at that.

  • Oops, the temperature is 72 degrees, so we have temperature here, so we have temperature.

  • So that's the text.

  • It gets printed out, and then the value of the variable for temperature is 72 degrees Now.

  • One of things to realize, though, is you know you have to be thinking about how things refresh.

  • And so when I touch the temperature sensor here, the tempeh cure for this temperature sensor is going up.

  • But you'll notice that the temperature on this Web page doesn't go up, and the reason is is because the Web page doesn't auto refresh.

  • So if you want to see what the current temperature is, you hit the refresh, and then when you refresh, it is then up to 86 degrees, refresh it again.

  • Now it's up to 87 degrees.

  • I take my finger off, and so the temperature should start cooling.

  • Censorship start cooling, and as we can see it goes down to 83 degrees.

  • And so again, this is one of those things you have to be thinking about with your code.

  • And you have to think about things such as, How is the variable?

  • Going to refresh is an automatic.

  • So like in the cereal monitor, we simply have a delay.

  • And in that delay delays how often things get refreshed.

  • But it gets refreshed automatically.

  • Or if you come to something like a Web page when the questions you're gonna have to ask yourself is, How are you going to refresh something like this temperature sensor?

  • Because think about it for a second, right?

  • Let's say you do all this, you create the temperature sensor and then you put this on some kind of, you know, screen in your office or in your computer lab.

  • Well, if it simply static so it takes the temperature that it was at the moment in time, you loaded the page and then it doesn't change.

  • Then that might not actually be that valuable to you, because the temperature may have changed quite dramatically.

  • So something that you need to be thinking about is, Do you want to add like a browser plug in to auto.

  • Refresh the Web page every minute, 30 seconds whatever else?

  • Or do you want to add some kind of script into the Web page so that the Web page itself auto refreshes itself?

  • Now, now how you do that and why you do that.

  • It would be situational and some in some situations you would want.

  • The page is simply auto.

  • Refresh itself in other situations.

  • You would want to be able to control that again, maybe through a browser extension, something like that.

  • But that is what would be one of the things that you have to think about.

  • So there we go.

  • I say its temperature of 72.96.

  • If we go over here to the Arduino, this is a serial monitor, and that shows us the information about the client that that's connecting to its host.

  • 1 72 16 42 5 Max.

  • A user agent Mozilla some of some of the other information here so you can have an idea of the computer that's connecting to this.

  • Aren't we know project?

  • And that's really all there is to this just a little analog sensor connected you the WiFi, then we're able to go and access it over over again just a standard I p based network and take a look at it in our Web browser.

  • So that's the basic project we use.

  • The yard we know, you know, with WiFi, we use an analog temperature sensor, and now we're able to see what the temperature is from anywhere in the world using a simple Web browser.

  • Obviously you have to add support forward and other things that might be involved in trying to access this from the outside world.

  • But this is the basic idea.

  • Again, this this has a standard i p for I p address.

  • You have poor 80 and then all you do is you're able to open up the interface using a Web browser and see whatever it's coded to see Now the cool part is, as we start to create Maur complicated projects is that you can have Maur sensors connected to a single Arduino boards.

  • You gave me pulling a lot of different information in or again what we're gonna one of things we're gonna be doing in the future as we can create hyperlinks to do things such as turn on fans.

  • So just like we've created systems in the past to automatically turn on fans if the temperature gets too hot, one of projects that will dio is will be alerted that the temperature is too hot, and then we can manually turn on the fan or manually turn off the fan again.

  • That will.

  • That will show you how, through a WiFi connection you can turn on and turn off motors again, whether that's a fan, whether that's a water pump with that some kind of compressor or something else, basically any kind of motor driven device you can turn on and turn off simply by using a Web browser, going to an I P address and being able interact with the art we know board.

  • So that's all there is for this particular project.

  • Again, with this particular project, I did notice my full five bolt connection here is only putting out 4.85 volts.

  • So as far as the temperature is concerned on here, if I was gonna put this into a production environment, I would probably go into that basic temperature math, and I would just add 51 of locations, but that is something you're gonna have to think about because again, like if you're looking.

  • But you're putting multiple templates your sensors around your environment and you're trying to analyze and see how the temperature reacts in different areas.

  • The first, the first thing that you need to do is make sure that they all have the same baseline reading the temperature.

  • Here, make sure the temperature here if you have all five of them, let's say make sure they're reading all the same temperature before you deploy them to where they're gonna go because of one is reading two degrees too high and another is reading three degrees too low when another Reed is reading accurate.

  • And then you put those out into the real world without trying to modify things, tweak things to make them have the same baseline.

  • Then the numbers that you're gonna get are going to be garbage.

  • How do you know?

  • How do you know if the temperatures or the readings that you're getting shows something or if the temperature readings that you're getting are simply incorrect and therefore they're pretty useless.

  • So just one of those things to remember again.

  • If you're gonna be dealing with Arduino, that would suggest that you go out and pick up a multimedia multi meter for issues like this again.

  • Is this a very simple way?

  • You just plug this into the fireball connection and see is five volts actually five volts, One of most important things in technology with the most important lessons I can ever sees you and technology, Are you receiving the results?

  • You're supposed to be receiving so much trouble shooting so much trouble.

  • Shooting can be solved by simply plugging and multimedia or doing something else and making sure if it says five volts that you're actually getting five bowls.

  • Because if you're not actually getting five volts, that all the other troubleshooting that you're gonna do is basically just a waste of time because the problem is, is you're not you're not getting what you think you should be.

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.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

Arduino Uno Wifi溫度傳感器 (Arduino Uno Wifi Temperature Sensor)

  • 10 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字