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 this video, what we're going to do is we're going to use in Are we?

  • No, no, no WiFi board and an L E D.

  • And we're going to go to a Web page that's been created by the Arduino.

  • You know, WiFi and using hyperlinks we're going to turn an led on and off.

  • Wyness is significant.

  • Wyness is important is because this is showing you you can connect to the Arlene.

  • Oh, you know WiFi and not simply receive information through sensors or inputs, but actually manually trigger events to happen.

  • So again, imagine in some kind of environmental systems, and you see the temperature has gone above a certain level, you may not want a fan to automatically turn on.

  • He may want a notification that the temperature has gone above a certain level, and then you may want to manually decide whether or not to turn on a fan.

  • How many fans you could have?

  • I don't know.

  • Five or six or 10 Fan's connected to an artery?

  • No.

  • You know, actually, turn on multiple different fans.

  • So what this allows you to do is it allows you to interact with your doing.

  • You know, wife, er WiFi over a WiFi network through your Web browser, not simply to receive information, but also to trigger physical events to happen.

  • So with that, let's go over the workbench.

  • I'll show you how to build this little project.

  • Then I'll go and show you the code and show it all together for you.

  • So for this project, all I need is again we're gonna need, are we?

  • No, no, WiFi.

  • We're going to need an led.

  • And since we're using an led were already need a 220 ohm resistors, we don't blow out our led, we're gonna need the bread board, and we're going to need a couple of jumper wires, so this is pretty simple.

  • We simply attached ground to ground on the yard.

  • We know, you know, with WiFi board, and then we're going to be using a pin number nine for this particular project.

  • So I simply connected the positive to pin number nine, and now that's all it takes to build this project.

  • So will be uploading the code obviously off of our computer.

  • But again, it is important to understand with this particular project, that this could be entirely wireless.

  • So if I use something like this little USB battery pack, I can have this completely, completely separated from any other computer system, be able to interact with the WiFi board, using my my Web browser and be able to turn on and off.

  • This led again without this having to be connected to a computer at all.

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

  • So here's the code for this little project.

  • It see it may seem a little bit complicated, but as always, if you read through it, you will start to understand what's going on.

  • It will not seem nearly as daunting as when it first appears.

  • So the first thing that we're going to need to do is we're going to need to include that networking libraries so that this artery no, you know, with wife I can actually communicate over WiFi s going to pound include Orion include the SP I library and the WiFi nine libraries are going include those two libraries.

  • The next thing that we're going to do it since we're going to be turning and led a light on and off, we need to define a pin for that led light of digital pen we're gonna pound to find We're just gonna call it led, and it will be digital pin number nine.

  • Then we have to give the information for starting up the Web server.

  • So we're going to Char S s I d.

  • That will equal for me.

  • It's test.

  • I've created a guest network with test.

  • That's my S s I d sharp ass.

  • I have.

  • This is blank.

  • If you have a password, you would pluck it in here, then end key index.

  • If you have multiple keys.

  • Different numbered keys for your WiFi network.

  • You would put the key index here 012345 I'm not worried about that, so I just have it at zero now, Then to come down, we have to create a variable for the status of our WiFi network.

  • So we're gonna create that end status equals currently basically w l idol status.

  • So we're gonna create the variable and set it to idle.

  • The next thing we have to do is we have to say what port number the server was going be working off.

  • So we have WiFi server server Edie.

  • So this will be working off of standard Http.

  • Poor 80.

  • Leave it that way, unless you really need to mess with it.

  • The next thing that we're going to do is we're going to create a string.

  • So this is a little new for this particular project and basically what this string is going D'oh!

  • Is this string is going to be used to parse whether to turn the law like the light on or to turn the light off.

  • So, basically, we are going to create a variable, cold read string.

  • We will set a value to that.

  • And then what we're going to do t turn the light on or off is we're going to read that variable and to determine whether or not to turn the light on and off.

  • So we're just going to set that a string and read string, and we're going to send it as blank.

  • They were gonna come down the first thing that we need to do is pin mode led outputs.

  • We're gonna set led pin number nine to output.

  • We're then going to do serial dot begin 9600.

  • So this starts the serial monitor, then passed that we're going to do what's required in order to start the WiFi.

  • So while status equals not connected, this is going to print out a serial monitor attempting to connect to test, then the status.

  • This is what connects us to the WiFi network.

  • This feeds E s s I d.

  • This this feeds the password, and then it's going to delay for 10,000 milliseconds or 10 seconds.

  • Once this has actually connected, then the server is going to begin.

  • It will then print out on the serial monitor.

  • It will print out what the s s I d is and what the i p addresses again.

  • You're I need that i p address in order to be able to access.

  • You're a little aren't we know device through the Web browser, then passed that we're then going to go into the loop.

  • This is actually going to be all the code that's going to be running to give us our fancy little Web page.

  • Ah, WiFi.

  • A client client equals server not available.

  • So we're saying the server is available if there's a client.

  • So if something tries to connect to the yard we know, then it's going a serial dot print.

  • So this will print out on the serial monitor Serial Monitor New Client, and this will basically used for giving the client information whoever is connected to the Arduino, then what it's got to do is wild.

  • Client is connected.

  • If Client is available, Char C equals client dot reed.

  • If Reed string dot length is less than 100 then do the following.

  • So it's kind of interesting.

  • Here is we talked about this before with this whole HRC client read.

  • So what this does is it allows the Arduino to parse what is being sent to it from the from the Web browser.

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

  • So this whole car see allows you to step through the process, basically, read the information coming in from the Web browser, character by character, by character, by character.

  • And then when you get to a new line, then it knows to be a bit.

  • Send something back to the Web browser.

  • Well, the interesting thing here is not only are we going to have used this to parse on know when to send something to the Web browser, but we're also actually going to use this in order to read what's in the U.

  • R L so that we can then determine whether or not to turn the light on or off.

  • So if we come down here to be, if else statements down here, basically what this does is says, read a string dot index of So basically looks at what's inside the reed string variable.

  • And if it if it is light on, so if it's greater than zero.

  • So basically, if this exists within that you are l then turn the light on else.

  • If light off is greater than zero light off exists within that read string, we're going to turn the light off.

  • So this is kind of interesting here where we're now, we're now using the information sent back and forth.

  • We're parsing that in order to determine what to d'oh.

  • So we're gonna come down here basically, if C equals next line.

  • So again with here parsing through that information, So if it's next line, then what we're going to do is run a print to the client.

  • So what this means is prank to the Web browser, and all we're doing here is we're creating two hyperlinks.

  • A ref, this says light on and then turn on light will actually be shown the Web browser break break a pref light off, turn off lights.

  • So basically, when I click this link here, light on is going to be sent through the earl.

  • And when I click on this link here, light off is gonna be sent to the girl.

  • You will notice that we have back slashes here.

  • Remember, those black slashes are used in order to to tell the art.

  • We know to ignore that as far as the Arduino code is concerned.

  • So make sure to put these on the's.

  • Backslash is over these escapes anywhere you see something like a double quotation mark and you're gonna be sending that information somewhere that the art we know itself isn't supposed to pay attention to make sure to put that escape.

  • So if you're If you look at something like this and all of a sudden you see black and here see how this is blue, and then all of a sudden, this part is black.

  • Then you know, there's probably an issue, and if you do escape and everything is blue, then that will do better for you.

  • Then what we're gonna do is we're gonna come down here and we're going to DeLay for one millisecond.

  • You'll notice there's a couple of delays in here, and this is something again when you're Cody and you have to play with whatever you're dealing with for some reason when you're when you're dealing with this with the yard, we know you know with WiFi.

  • If you give it just a slight little bit of delay, you give it a little bit of time to think about what is doing.

  • The device works a hell of a lot better.

  • If you don't put these delays in here, you might get some quirky issues, so basically it will print out.

  • We'll print this out onto the screen and then it'll simply delay for one millisecond.

  • Then what's gonna happen is if Rita String dot index of So it's going to read.

  • The string is gonna read, Read the information.

  • And if you see dollar son, if, er, if it sees a question mark light on and is greater than zero.

  • So basically, if it sees this and what is going to do is digital, right?

  • Led so digital pen nine high.

  • So it's gonna turn digital pin nine on.

  • We're gonna delay for one millisecond else.

  • If reed string dot index off equals light off is greater than zero, we're gonna do digital right led low that turns the led off delay for one millisecond.

  • So basically, it's gonna take a look.

  • If Light on is there is gonna turn the light off White off is there, it's gonna turn the light off.

  • One interesting thing is, it's looking for this, So as long as this is there, it will function so literally if I went up here and I went 1111111 Right, So as long as it sees this right, that's all it's looking for.

  • So even though all of this gets passed, as long as that part is in there, that's all that this particular if statement is looking for.

  • So that is one the thing just to keep in mind.

  • So if you're passing these kind of values and they're very, very, very similar to each other, you might run into issues when you're doing something like this.

  • So just just kind of think about that a little bit, But otherwise, basically, that's it.

  • So basically, when these when these values get past this point, reed string dot index off sees light on turns the light off sees light off.

  • Turn the light off.

  • You were gonna come down here after this read string.

  • We're gonna put back to Black.

  • So this empties out the reed String s O that we can make sure that it's empty.

  • So it's it's waiting for the next command.

  • Then it's going to delay for one millisecond again.

  • That's going to client stop.

  • So his client not stop and then serial dot print line client disconnected.

  • So this is going to disconnect that.

  • And so this is the code that is required to create a web, pay with hyperlinks and be able to turn the light on or off.

  • So here we are, so going to be I p address is the I p address of this artery.

  • Know Kunal with wife eyes 1 72 16 42 not five.

  • Just to make us a little bit more interesting.

  • And you can see you can see no wires.

  • Ma, this is not This is not connected to my computer at all.

  • So this is entirely self contained.

  • We're powering this off of this little USB battery pack right now, and all I could do is go over here to turn on light.

  • I click this well, and the light turns on, you'll notice up here, you see, within the u R l that it says question mark alight on.

  • And so its able to read that.

  • And so it turns the light off.

  • Go over here and I click light off.

  • What?

  • The light is off again.

  • You appear you see question mark light off.

  • And so that is what the script is parsing in that if else statement and again I could just go back and forth and turn the light on and turn the light on.

  • And then every once in a while, it's a little for Pia on.

  • Turn the light on and off and yea, you can turn an led on completely from WiFi using a weapon.

  • It does get a little quirky.

  • Every once in a while, you have to refresh, but that's basically it.

  • So this is being written to this Web browser from the yard we know with WiFi, and then we're able to click again, turn lights on and off again.

  • When we were dealing with his digital, Penn realized this could be connected to an led, or it could be connected to some kind of motor module or something like this.

  • The main important thing here is that we're able to turn a digital pen on it off.

  • So that's our little project again.

  • No hands, no hands.

  • I click beyond and the light turns on.

  • Click the off on and oops, it's a little quirky.

  • It's a little Korpi sometimes, and the light turns off during done on Turn it off.

  • There you go with that shows you WiFi.

  • You go when you can play with this code and again.

  • All you're doing is you're turning the digital pin on and off.

  • So whether you're turning on a motor, what whether you're connecting to a, uh, a motor module of her turning on lights again.

  • Whatever could be triggered with that digital pin, you are now able to trigger it.

  • And so that's really all there is to this particular project.

  • I want to show you here how you keep building all in all these these different components to create an evermore complicated piece of technology.

  • So again, when you see me using a nard, we know and I'm turning led on and off.

  • Well, that doesn't seem a process, But then I'm using the yard.

  • We know and I'm reading from a temperature.

  • It's like, Well, that's nice, But then I use the yard we know to read from the temperature and turned the l e d light on.

  • Well, that's kind of curious, but then you connect that toe WiFi that gets a little bit more interesting.

  • And then you start to have a temperature sensor and you're able to start controlling things manually over WiFi.

  • And that's where you start to get too complicated devices that actually become pretty important in the real world.

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.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it