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 this video, we're going to take an Arduino Oh, no WiFi board and ID and along temperature sensor, and we're going to create a visual alert temperature system.

  • Basically, what we want to do is we want to be able to see what the temperature is in a certain environment, and then we want to be alerted if there's a problem.

  • So what's gonna happen is we're going to be able to go to the i.

  • P.

  • Address of the art we know, you know, WiFi board.

  • When we go there using a Web browser, we're going to simply see a very large number, and that's going to be at the temperature at the analog sensor is currently reading.

  • So we're going to make that in a very large fund.

  • Now, if the temperature is under 76 degrees, we're going to make that number green.

  • So this is the number.

  • It's green.

  • So it's good evens above 76 degrees but below 82 degrees where I want to see that very large number and it's going to be yellow.

  • So it's going to show us the number is gonna show us the yellow to say, Hey, there might be a problem.

  • Maybe not.

  • Maybe not.

  • Maybe you know what's going on, but you might want to take a look into it and it's about 82 degrees.

  • We're gonna see that large number, and it's going to be in red now.

  • One of the things that we have to do with this system is when we go to a normal Web page that went page on.

  • Lee refreshes when we tell it to refresh.

  • So that's a problem that you can get into when you're using a Web page in order to look at readings coming in from a sensor is it only refreshes when you tell it to refresh, so you know you first turn it on.

  • You first opened that page and the number is good, and then you walk away and you think all day that the number is good because you've never refresh the page and so you don't have to manually go over and refresh the page.

  • And so one of the things that we're also going to dio with this particular project is we're going to add metadata that forces the page to automatically refresh itself every five seconds.

  • So every five seconds, it will refresh.

  • The Web page is being presented by the art.

  • We know who you know, WiFi board.

  • And so as the temperature goes up and as the temperature goes down, that page will dynamically refresh so that we're always looking at relatively recent data.

  • And, you know, our server room isn't overheating, but we're sitting there looking at the screen that was literally created five hours ago.

  • So this project we're gonna be using the Arduino, you know, born a simple analog temperature sensor.

  • Gonna throw this on a bread board and show you how this works.

  • So with that, let's go over to the work bench.

  • I can show you howto build the physical components of this project.

  • Then I'll show you the code and I'll show you how all this comes together.

  • So these are the only components we need for this particular project.

  • Got a bread board.

  • We've got our Arduino, you know, with WiFi and we've got an along temperature sensor.

  • We should the analog temperature sensor into the bread board.

  • We plug in the ground, we plug in the V C C, the power, the 50 power and we plugged in the sensor.

  • So those are the only connections we're gonna need to make this project work.

  • From there, we bring this over, we plug the power the BCC into the five old we plug ground into one of the ground connections on the way no more.

  • And we plugged the sensor.

  • We're going to be using a zero again.

  • This is an analog sensor.

  • We're gonna use one the analog connections, and we plug that into a zero.

  • And with that, that is literally other than plugging this thing in.

  • That is all you need to do again.

  • I will remind you when you're using something like the WiFi board on, especially when you're gonna be accessing it through a I P address or such, you do not have to have this connected to the computer.

  • Once everything is set up again, you can plug in a little USB power supply like this, you can plug in a power adapter, whatever.

  • This could be 100% separated from a computer and continue doing whatever it is you've told it to do.

  • So with that, let's go over to the computer and I can show you the code how to build this thing.

  • So here's the sketch for this particular project.

  • Now it's going to start to see him a little bit more complicated than other sketches that we've done in the past.

  • But if you just break it down to its core components, you will realize that it's rather simple.

  • One of the big things with this particular sketch is that we're gonna be coding for the Arduino.

  • Plus, we're going to be using HTML, and we're going to be using CSS.

  • So this is one thing where a lot of people ask me, Eli, what's the best programming language I should learn?

  • What programming language should I learn as if it's an individual thing on what you find in the real world is many times you're going to be using multiple languages even to do something relatively simple.

  • Literally.

  • All we're going to be doing is showing, you know, that the number, the number for the temperature reading and a changing the color and size of it, and to do that.

  • We're gonna be coding for all we know and are going to be using HTML.

  • And we're going to be doing CSS even for a project as simple as this.

  • So let's go up and start taking a look at this, eh?

  • So the first thing we need to do is we need to include the libraries that are required for the WiFi connection.

  • So this is for the WiFi and the communications protocols.

  • We're going to include SP.

  • I got eight library and WiFi Naina dot h library.

  • This simply gives us what we need to be able to connect to a WiFi network and be a bit communicate.

  • Then the next thing we're going to do, since this is a temperature project is we need to define the sensor pen, so But what pin?

  • What analog pin is tthe e the analog temperature sensor on.

  • And so we're going to call this sensor pin, define sensor pen, and we're going to set back to a zero.

  • From there, we're going to go down, and we're going to set up the WiFi information.

  • So Char s s idea.

  • So, basically, what is E.

  • S s I d I've set up a guest network on my system called Test.

  • So the SS ideas test the jar past.

  • This is where the password.

  • I've set this to blank because my network I've said it to blank.

  • So I don't have to doing troubleshooting while I'm doing these videos.

  • If you have a password, plug that in there, then we have any key and next.

  • So if you're using different keys on your WiFi network and you need to give the index number, this is where you would do it.

  • We don't have that, so it is simply set to zero.

  • The next thing we have to do is we have to create a variable for the status for the wireless connections we create and status equals.

  • W l underscore.

  • Idol understood, underscore status.

  • So this simply creates that variable, and it's that's the value to.

  • Basically Idol will use that for the connection and then WiFi server, and then we're going to set the server to poor 80.

  • So this is the http pork that we'll be using, so we're just kind of plug in 80.

  • You can modify that port number here if you want Thio the next thing we're gonna do is we're going to create two variables for the if else else.

  • If else statement that we're going to be dealing with us faras the temperature is alert, it's concerned.

  • So basically, when we're dealing with this, there's two numbers that we care about.

  • What is the high temperature?

  • What is the Oh, no.

  • This is way too hot tempered cure.

  • And that's the variable high temp that we're gonna set that to 82 degrees.

  • And then what's the good temperature?

  • What's the temperature is as long as it's under that we're happy.

  • And so I just simply set that to 76.

  • So I have created these variables, and I've set these variables here to make life easier if we need to modify it so we can If I need to modify these numbers in the future, I can simply come back to this one place and modify the number versus having to go through here and change it multiple times.

  • Remember, the more time you have to modify something, the more likely it is.

  • You will mess it up so I could just simply write the code down here I can secure simply say temperature F is greater or equal to high temp, and so that's the value of that variable.

  • Now, instead of having to go through and modify the number five or six times, I can simply modify that one place up here with these two variables then we're gonna do is we're gonna come down here and we're going to set up the environment to the first thing that we're gonna do is cereal dot again 9600.

  • So we're starting a serial monitor.

  • The next thing that we're going to do is we're actually going to start the WiFi connection.

  • So while status does not equal W l connected serial, it's gonna print out to the serial monitor attempting to connect to network named and then it's going to give the name test.

  • Then the status equals and we're using the function WiFi not begin s s I.

  • D on pass.

  • So it's gotta feed the s s I d and the password of dysfunction, and it's going to try to connect to the WiFi network, think when delay for 10,000 milliseconds or 10 seconds.

  • So while it's not connected, it's just looping through this when it finally connects.

  • Then these little server begins.

  • It will actually begin the server service.

  • Then it'll serial about print S s i d with E s s i d is.

  • And then this is how you get the i.

  • P.

  • Address and printed out.

  • So print out the s s I d and print out the I P.

  • Address again.

  • This is the kind of thing you need on these types of projects because you need to know what the hell d I p addresses.

  • You can code all this perfectly, but you don't know where the I P addresses.

  • Then it's gonna be impossible to access.

  • And that's now the environment that's set up now we're gonna go into a loop.

  • The first part of loop.

  • This is how we are able to obtain the temperatures.

  • So we done analog temperature sensors 1000 times.

  • At this point, I'm not gonna go into this, But basically the important thing to understand here is this is how we get the value for either temperature, see, temperature Celsius, or this is how we get the value for temperature f temperature Fahrenheit.

  • And that is what we're gonna be testing against and the If else if else statement, then we're gonna come down and we've got all this code right here again has get written out on.

  • Basically, this is for the communication between the Web browser and the Arduino.

  • Again, we're coating this out so we actually have to tell the art we know how the communication happens.

  • You know who contacts who first, who gets to talk someone so forth.

  • And so this simply says WiFi client Equal server available So the server is available.

  • If there's a client, it's got a serial monitor print.

  • It's got burnt down serum.

  • I'll tow new client, and that is going to do while client is connected.

  • If client is available, basically, what this means is going to print out the the client information.

  • So when your Web browser can next to the yard, we know it's going to print out that information on the serial monitor and then when it gets to a new line, So if C equals new line and basically, if current line dot length equal zero, then we start actually sending stuff to the client to the Web browser on.

  • This is where we get to the meat and potatoes of the pride that really project that we're doing today.

  • So the first thing that we have to do here before we get to the F else if else statement is we're going to actually print out some made of data on what this is for is tohave the web page auto refresh itself again.

  • One of things have to be thinking about when you display information is how often is that information going t be refreshed.

  • So if it only gets refreshed every hour, that means literally it might be what you're seeing.

  • Maybe 59 minutes old when you're seeing it.

  • And so again, especially for something like a temperature sensor or a temperature alert system you anything about how often you're going to refresh and do you want a manually refresher?

  • You want to have it be automatically refreshed for this, since all we're doing is literally were simply printing out a number in a pretty color.

  • Then I want this to auto refresh on its own.

  • Have it having the pig itself.

  • Auto refresh is a useful thing.

  • And so what we're gonna be doing here is we do client dot print line head Meta http.

  • Hyphen equals equals refresh.

  • So there's a saying refresh content every five seconds.

  • So basically doing this, it refreshes the content every five seconds.

  • Now you'll see these backs slashes here.

  • So basically, if you normally, if you're writing this in CSS, this right here is what it will look like.

  • But the problem is, is when you're when you're writing this code, you have to be able to tell the Arduino What code should the Arduino care about?

  • What code is a Web browser gonna care about?

  • Right.

  • So since we print everything between the double quotation marks, if we don't escape out, that's what a backslash is that we don't escape out.

  • Essentially, what's gonna happen is the yard we know is simply going to send this right.

  • Send everything between the double quotation marks, sir.

  • Yes, sir.

  • And so it's literally gonna do what he told her to do, which is that that's not useful.

  • So what you want to do is you put in the back slash you put in the back slash and escapes out characters that you don't want the yard we know to interpret.

  • So basically, what happens is the Arduino will get Thio that backslash and we don't know the next character.

  • It's not for me, it's for something else.

  • And so what will happen is then what will be printed out is the back slashes will be ripped out and you'll just get a nice, solid piece of CSS or HTML or whatever here.

  • So that's a big thing with the backslash is any time you get to a problem like you're writing something and you start to see black like this, you know you're running into an issue where the Arduino thinks that it's its finished interpreting what it's supposed to interpret, and you put a backslash in there and make sure everything is in blue that's supposed to bloom.

  • So what this is going to do here is going to say for the entire Web page, refresh every five seconds.

  • Then we're gonna come down here to be, if else, if else statement.

  • So we're going to say, is if temperature F dip your Fahrenheit is greater or equal to high temp, the value of high temp the value of high temp is 82 so if it is greater than 82 we're going to new client, not print line.

  • And then what we're saying here is we're doing the tag for H one.

  • Pretty little little tag or putting little CSS here saying h one style equals color red.

  • We're gonna make it color red fought size 400 pixels.

  • So we're gonna make it big.

  • You're gonna notice we've got these back slashes in here and those air to escape out of the double quotation marks Don't escape by the double quotation marks.

  • You will run into problems.

  • So this starts the H one tag.

  • Then we're going to a client, not print or simply do the value of temperature, F whatever that is there already a client, not print line and closed the H one tax.

  • What is gonna dio is this will print out whatever temperature is in Fahrenheit in big and red, then else if else if else If temperature Fahrenheit temperature F is less than high temp, less than 82 temperature F is greater or equal to good.

  • Tamp, go up here.

  • Good.

  • Tim is 76.

  • Um, then what we're going to do It was basically the same thing.

  • The difference being we're going to print it in yellow.

  • So this is gonna print it out and yellow again at that for 400 pixels.

  • Then if we go down else so it's not above 82.

  • If it's not between 76 82 then it should be good.

  • And so we're just simply doing else in the exact same thing we did up here.

  • The difference being is the color is going to be green now, then a SZ Far as the WiFi thing is concerned, we're going have to break and then we're going have basically all of this here, which again is basically copy and paste.

  • This is what's required in order.

  • Have the Arduino to understand how the wife I communication is supposed to happen.

  • And then with that, all we have to do is we simply have to upload the code.

  • We're gonna upload the code there, so it's upload a kn and then once it's finished uploading, we're gonna go to the serial modern.

  • So we go to Syria monitor.

  • And so now it's attempting to connect to a network named Test.

  • So it's now currently trying to connect to that S s I D.

  • And this will take a few seconds again.

  • 10 seconds in the real world and the real world, 10 seconds is no big deal.

  • 10 6 10 seconds While you're trying to teach a class seems like forever But they're ago We gotta connected So it's now connected S s I d It's connected Thio the the test WiFi network and this is its i p address.

  • So we can simply copy that if we want, we can go over to Google Chrome open up Google Chrome dual control V en er And there we go.

  • So look at that.

  • Look at that.

  • So we now see, that's a temperature sensor says 73.84 degrees, 73.84 degrees is, of course, lower than 76.

  • So it's good Now look at that auto refreshed after about seconds.

  • And so we see.

  • Now see, it's 72.6 degrees.

  • Now what I'm gonna do is I'm going to put my finger on the temperature sensor like you normally do for these projects, and then a couple of seconds is going to auto refresh.

  • And when it does look at that.

  • It's now 83 degrees.

  • Oh, no, it's too hard.

  • It's too hot.

  • So now I'm gonna take my finger off.

  • You never took my finger off.

  • It's now up to 86 degrees, but you can see how it's automatically refreshing.

  • Now we get to 81 degrees 810.75 so that's a little bit below 80 to re.

  • So that's now Yellow comes down to 78.23 degrees and then should keep coming down since my finger is off.

  • So what we can see here is that we've created a very a large number.

  • So again, this is something that you could use in a very standard Web browser.

  • Imagine you.

  • You know you have raspberry pi laying around or something like that, and you want to be able to have some kind of display for different tempeh cures for different places again, something like a server room.

  • So this shows you how you can have this are we know, you know, WiFi sitting in a server room.

  • It's connected to your WiFi network, and then you can have a display like this up anywhere that's connected two to the network that can connect to it to the I P address, and it will simply refresh and show you what the temperature is and will alert you if the temperature gets to war again.

  • Like you just said it here at 72.96 degrees and auto refreshes Oh, no, it's 83 degrees.

  • Get the O.

  • So that was another a little project using Are we?

  • No, no WiFi And, of course, our trusty little analog temperature sensor.

  • I like using the analog temperature sensor because it gives you the ability to change the values rather dynamically and have your code with those those if else if else statements, you know, be able to trigger a different events to happen.

  • But again, with this kind of thing, remember, you can have the same type of stuff with motion sensors or with distance sensors or some other type of sensors.

  • Basically, all we're doing is we're taking that.

  • We're taking that sensor input, and they were saying, depending on what that sensor input is, do these things.

  • You know, before we we've turned led lights on.

  • We've written too LCD screens.

  • We've turned motors on again with turn like fans on, and now all we're doing is we're printing out to a Web page basically to a Web browser.

  • And this is what I really want you to be thinking about with Arduino projects and with Coyote.

  • Because back in the day, back in the day back teen years ago what we talked about input and output as faras computers were concerned.

  • We're talking about the mouse and keyboard as faras input, waas and output was you the screen or the printer input mouse keyboard output screen printer?

  • What I really want you to be thinking about now with these I o T projects is your input could be 1000 different times of sensors, and your output could be a lot of different things again.

  • You just need a little ready led, like going off.

  • You want a buzzer going off?

  • Do you want a big old display with a number that tells you something specific?

  • This is one of those things you have to think about the Io ti world.

  • It's not just simply it's not just simply text on a screen or a picture or something like that.

  • You really have to be thinking about what?

  • Okay, there is a problem the sensor has detected.

  • Something is either good or bad.

  • Now, now what?

  • What do you want to have happen again?

  • Broke out to an LCD screen.

  • You want a buzzer?

  • You want something on a web page?

  • Do you want something to be documented into a database or printed toe?

  • A file?

  • All of these things are possibilities with outputs.

  • And all of these are very relevant in this I t world.

  • So that's why that's why I think this kind of stuff is nifty.

  • Me and again, don't get too hyper focused when I show you an analog sensor or something.

  • A lot of people get hyper focused on, and I'm trying to show you the overall concept.

  • You take this, you copy and paste and figure out what you want to d'oh when the other important things to be thinking about with a small little project no is in this project where simply were essentially using three languages.

  • I know you don't really think about HTML.

  • CSS is languages, but but work with me here and this is an important thing you have to understand about this new world of technology is you're dealing with hardware.

  • You're dealing with sensors.

  • You ought to be thinking about output.

  • And again when we talk about languages.

  • So many people, when they think about programming languages, they say, What what language should I learn?

  • What language and what I want to show you here when even this exceptionally, exceptionally simple project we're using Arduino, which is a derivative c c++ where do using CSS and we're using html.

  • Even in this again, this is still less than 50 lines of code.

  • And so that's one of the things you should be thinking about once you start building these projects is it's not about one language.

  • It's like when we start making more complicated things well, at Java script, we're gonna add PHP within a short amount of time.

  • We may literally be using five or more languages for again.

  • It's something that is a relatively simple project.

  • So that's the other thing that I really want you to be thinking about.

  • Is it?

  • You're not gonna be learning one pride, huh?

  • Programming language.

  • You're not going to be learning one Technology is about learning all of this stuff and then figuring out how it goes.

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 WiFi溫度網頁提醒 (Arduino WiFi Temperature Web Page Alert)

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