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 be using our we know you know, a WiFi and L 298 in motor module, a fan and an analog temperature sensor to be able to create a wireless sensor that will be able to give you notifications and you'll be able to manually trigger a fan.

  • So a lot of the projects that we do, we have some type of sensor.

  • And then that sensor is what automatically triggers a physical event happen.

  • What's going to happen in today's project is we're gonna have the analog temperature sensor.

  • Basically, the Arduino, you know is going to continuously read from the analog temperature sensor, and then it's going to give an output that we can see in a Web browser, so it will show us a very big number for the temperature.

  • If the temperature is within the cool level, that number will be green.

  • If the temperature is in the yellow like the medium level, it will be yellow.

  • And if the temperature is in the high level, the temperature will be read.

  • Then, under that, there will be a manual links so that you can click and manually turn a fan on or manually turn a fan off.

  • So this is an important thing to be thinking about when you're administering systems.

  • Now it is great, and it is amazing to be able to have physical events happen automatically.

  • That is just an awesome thing to have happen, but there are.

  • Sometimes there are.

  • Sometimes you want to know that there is a problem, but you don't want systems to automatically try to rectify the problem.

  • You simply want to know that there's a problem and then be able to trigger a physical event to happen.

  • So what this is going to d'oh is this is going to continuously read from this analog temperature sensor.

  • Provide that in a format that you can use in a Web browser, and then if the temperature gets too high and you decide to turn on the fan, then you can click on a link and turn on the fan.

  • So with that, let's go over the work bench so I can show you the components that are involved in this project.

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

  • So here is the project as it's been built.

  • Unfortunately, this looks a little bit of like a mess, but I'll try to explain everything going on here.

  • So the important components for this basically what allows all of the actions of the outputs that take place is we have our art.

  • We know you know why.

  • Five board here and we have the l 298 in motor module here.

  • So these are the two main components that will give us the intelligence and the ability to actually trigger things such as the fan being turned up.

  • Now, if we're going to take a look at this l 298 in a motor module, one of the things I have talked about in the past with these models is that there are multiple ways in order to power the module and a power the whole system.

  • When you're using one of these models, one of the ways that you could do it is you can actually use the ven the pen on the Arduino board in order to power of the module.

  • Another way that you can power the module is simply by connecting it to a to a 12 volt or up to a 35 will power supply and connecting the yard.

  • We know on its own circuit.

  • Or you can connect this with up to a 35 hold power supply and then connect the Arduino to the L 298 and module.

  • What I've decided to do today is just keep this on two separate circuits.

  • So the l 2 90 in module is being powered by this 12 01 connector power supply.

  • And then the Arduino currently is simply being powered off of the computer.

  • So realize power is coming in from two different sides.

  • Now, One of the reasons that I did this is that we're having a weird problem with the analog temperature sensor.

  • The M L.

  • A temperature sensor was acting really quirky when I actually connected the power supplies and these things were trying thio power each other when nothing was connected, it would work fine.

  • But when I would connect the 12 volt power supply to the Arduino board, power would come in power would come in to the analog temperature sensor, but the output that would come out would get all wonky.

  • I'm honestly not sure why that occurred, but it was a problem that, frankly, I couldn't get around.

  • So the way to get around it was by simply putting these these two devices on different circuits.

  • So this is what the l 298 and is getting powered off of.

  • And then you could have the Arduino board be powered off a computer USB battery pack something like that.

  • Now, one of things you'll notice I have the power connector here.

  • He uses a normal barrel connector, and what I've done is I've used one of these cool little adapters.

  • So these air nice adapters, you could buy a whole pack of five for about $6.

  • And what this allows you to do is it allows you to take a normal barrel power connector into one side and then be able to split that out to normal wires on the other side.

  • So that's what I've done here.

  • So this is a normal power adapter with the barrel connector that comes into this adapter.

  • This adapter that allows me to screw down your ground and your VCC wires in the ground vcc wires, then going through the l 298 model.

  • So this is a great valuable little thing, then passed that as far as the L 298 and Margo goes one side, I've connected the fan s o.

  • The positive is into, uh, I am one the ground, isn't it?

  • I to ports on the l 298 and module and that goes the fan.

  • And so this allows me to power the fan and turn the fan on and off from the Arduino board.

  • Then for the Arduino board we have, they're doing a boar connected in a so the e n a wire.

  • This is what controls the speed of the motor or the fan.

  • So we have the wire, we have the eye and one wire, and we have the eye and to wire those come over to the digital side on the art, you know, you know, with WiFi then past that.

  • So all of this, all of this is what's required for the motor.

  • But then again, we also have the temperature sensors.

  • We have our analog temperature sensor over here again.

  • As always, we have 50 for VCC power.

  • We have the ground and then the the centre.

  • The centre wire goes for the analog sensor.

  • And so that comes over.

  • And I have that plug into a five today.

  • So basically, this is how everything is set up compared to how we've dealt with the l 298 in motor module before.

  • The really only difference here is that we are putting it on its own circuit.

  • And again, this is an important thing to understand.

  • Whenever you're dealing with Arduino projects is remember the artery No board itself.

  • It can always support upto 12:01 a.m. So if you try and put a more power through, you most likely blow it up, which is bad.

  • And so when the questions is well, how how are you going to control motors?

  • How are you going to control electrical devices that require far more power than 12 volts?

  • That's where you could use something like this motor molecule.

  • So this motor module is able to support up to 35 holes.

  • Some of these motor modules, depending on whether specific specifications are may be able to support up to 45 golds.

  • So what, you could d'oh!

  • As you can have your old wino board on one power, surf it and then just have the control wires coming over to the other electrical stuff that you've set up and then these air able to run off of more voltage.

  • So again, think about this for things like water pumps.

  • Again, fans remember, fans will basically spend as much powers you put through there, although spend faster and faster, that type of thing.

  • And so this is a reason why you may want to have everything on separate electrical circuits, but this is basically what we have set up for here.

  • I hope that makes sense.

  • I know it's getting a little confusing.

  • There's a lot of stuff going on, but really, if you just, you just go through and look at the code and you look at everything, you realize that it's actually not that complicated so that let's go over and take a look at the code.

  • So here's a code for this particular project.

  • It may seem a little bit complicated at first blush, but what you'll notice if you take a look at it is really We're just doing a lot of copy pasting a little bit of modification and add on to all the projects that we have done in the past and again.

  • That's really what any project is.

  • You take all the little components you created before blew them or duct taped them together to get something a lot larger.

  • So the first thing that we're going to do is we're gonna have to include the libraries for the WiFi communication SP I not H and WiFi Naina.

  • So this will allow us to communicate with yard.

  • We know board over wifi.

  • Instance, we have that analog temperature sensor.

  • We have to define the temperature sensor pen.

  • So to find a temp sensor a five so the temperature sensor is going to connect to analog pan five.

  • Then we have to define the pins that are going to be required for the motor module s o on the motor manual.

  • E n A.

  • There's a pen called e n A and that is for speed.

  • There's I in one, and I and two I, and one is the first power pen on the motor module.

  • Ianto is the second.

  • And so speed is going to go to digital pen eight on there.

  • We know born I and one will get a digital pin nine and Ianto, go to Dick.

  • It'll pan 10.

  • They were gonna go down.

  • We're gonna set up everything for the WiFi.

  • So P r s s I d equals test.

  • I have a guest WiFi network set up on my network.

  • I have simply put the s s i d to test we have a car password.

  • If you have a password for your your network.

  • This is where you would put it in.

  • I have left mine blank.

  • Yes, I don't have to troubleshoot crappy password things while I'm doing all of this.

  • Then we have end key index.

  • If you're using multiple keys on your wife, I You would put something in here again.

  • 012345678 We don't have anything to worry about.

  • So it's just said it.

  • Zero then passed that we're going to create a variable for the status for the WiFi connection or just don't set that w ell idol status.

  • Then we're going to have a WiFi server and we're going to set the server to port 80.

  • So if there's a reason you want to be on a different poor, let's say you're doing pork forwarded from the outside world.

  • So maybe you want to do it on a different port.

  • For some reason, this is where you would change that port number.

  • Then we're gonna have a variable string and read a string.

  • This is going to be the variable that we're going to use to actually be able to turn the motor module on and off.

  • We'll deal with that later.

  • And then we create to an integer variables for temperature.

  • So high temperature equals 82.

  • So it's 82 or above.

  • It will be considered a high temperature here and good temp.

  • So good temperature is we're just going to say, 76 or below.

  • So this gives us the variables for the temperatures so we can come back to this one place and modify the values for those variables.

  • If we need Thio, no, we're gonna do is we're gonna come down here.

  • I'm going to Southie Environment that this sketch is going to run in, so we do pin mode e n a I and one eye and two and we all set those two output those air digital pins so on, they're going to be sending information to the motor module, so we send them to output.

  • Then what we're going to do with that E and a pen is we're gonna analog right in a 2 55 So basically, we're writing to the e n a pen, and we're saying what speed we want the motor to run at.

  • We're setting it at 2 55 so you can change the speed with the motor.

  • Michael, between 022 55 0 is the slowest 2 55 is the fastest.

  • So you can modify that depending on what you want to dio.

  • I just sent it to the highest speed to make life easier for me.

  • Then we're only serial dot began.

  • So this, of course, starts the serial monitor so we can get some output from the cereal monitor while we're doing troubleshooting that such then pass that we're going to do what's required in order to set up the WiFi, actually connect to the WiFi.

  • So while status does not equal w l connected, it's going to print, attempting to connect to network named That's gonna be SS.

  • It's gonna be a test.

  • So it's gonna be attempting to connect to network name test.

  • Then status equals and he uses dysfunction.

  • WiFi not begin as this.

  • I d pass this passes this S s I d passes the password, tries to connect your WiFi delays for 10,000 milliseconds or 10 seconds.

  • So while that's little being this is what you see.

  • Once it is finally connected than we do server dot Begin, and then it will print out that the s s I d.

  • So you are connected to the S S I d.

  • And it will print out your I p address all on the serial monitors, A serial monitor.

  • You can take a look with the I P addresses, and then you can use that to get into the Web browser and be able to access the Arduino.

  • Then we're going to get down the meat and potatoes the actual loop of this particular sketch.

  • The first thing within this loop is all the math that is required in order to figure out what the temperature is.

  • So this is again copy and paste from all of our other analog temperature projects Reading voltage temperature, See temperature f This just this just pulls in, pulls in the information from the analog a temperature sensor on, then turns that into something that we can actually use for this.

  • We actually care about temperature after bitter Fahrenheit.

  • Then pass that again.

  • Another bit of copy and paste.

  • All of this here.

  • This is the the WiFi server service.

  • Basically, this is make the server available.

  • If there is a client while the client is connected, if the client is available so on so forth again, Basically, just copy paste.

  • We've talked about this before.

  • This is what's required in order to actually provide a website or suck to the client that's connecting to the Arduino.

  • Then we're gonna come down here.

  • And the interesting stuff is now past the IFC equals backslash in.

  • So everything here is kind of this new stuff that we're gonna be dealing with.

  • So the first thing that we're gonna do is client dot print lie.

  • So not serial dot print line client up front line.

  • So client up front line, this is going to print out to the web browser that's connecting to the art we know.

  • And the first thing that I want to do is I wanna have this Web page auto refresh so that we see what the current sensor reading is.

  • Remember, when you go to a normal Web page, it will print out once, and then until you hit refresh, you'll see the exact same thing.

  • So again we have a temperature sensor Temperature is dynamic.

  • It's going to be changing.

  • And so I want to actually see the temperature change as a canvas.

  • So that's why I put this meta http hyphen.

  • E quiver equals refresh content equals five.

  • So what this does is going to is going to have the Web page automatically refresh itself so you don't need another plug in or extension on chrome or Firefox.

  • It will refresh itself every five seconds.

  • So that's the first thing we're gonna do.

  • Come down here and we're gonna say if temperature af dumped your Fahrenheit is greater or equal to high temperatures are gonna go up here.

  • What's high temperature?

  • It's greater or equal to 82.

  • Then what we want to do.

  • Client.

  • So print out the Web browser H one style equals color red.

  • So we're using a bit of C.

  • S s here.

  • We want the color to be read and we want the fought size to be 400 pixels.

  • So it wanted to be really big.

  • Really, really big again.

  • If you're thinking about some kind of like monitoring type service, something that people can see, you want to think about how large you want the text.

  • So I want this to be a really big Then the next thing here it's kind of interesting is the margin hyphen bottom equals 10 pixels.

  • So again, when your thinking about creating the user interface, not only you have to think about the text size, but you also have to think about things like the border size or the margin size.

  • So when I print something out of 400 pixels many times the margin around it will also be 400 pixels.

  • Well, I'm gonna have to have these links below the temperature readout in someone somewhere close, right.

  • I don't need it like I don't have to say I don't wanna have to scroll down the page to find these things.

  • So by doing the margin hyphen bottom 10 pixels.

  • What that does is it creates a very small margin at the bottom after it's printed out the temperature so that it can then print out these links right below it.

  • So again, things to be thinking about his things, like such a margin.

  • So what it's gonna do do the H one and then we're going to simply plug in.

  • We're gonna plug in the value of temperature F, and then we're going to close the H one tack.

  • So basically, this opens the H one tag.

  • It says we wanted to be read.

  • We want to be 400 pixels.

  • You want the margin to be 10 pixels, then it's going to print the values or whatever that number is, and then it's going to close the tag.

  • Then below that, what we're going to do is we're going to print out these links.

  • So these links are now.

  • What's going to manually control the fan?

  • A ref equals basically forward, slash, slash question Mark fan on.

  • Uh, I was going to say Turn fan on where I do break brakes.

  • That's gonna be 22 spaces that we're gonna do a ref forward slash question mark fan off and say Turn off fan And we're going to close that when they're just going through the break.

  • So there's a space.

  • So what this guy do is in very large red.

  • It's going to say whatever the temperature is then below, it is going to say, Basically, do you want to turn the fan on or do you want to turn the fan off if we come down here else?

  • If temperature Fahrenheit is less than temperature high temp, so it is less than 82 A.

  • M.

  • Temperature F is greater or equal to good to temp, so we go up here and take a look.

  • A good temp.

  • Good Tempest, 76.

  • So what this is saying is, if it's below the high temperature, but greater or equal to the good temperature, then what we're going to be doing is we're going to be printing out temperature F, but we're going to be printing it out and yellow, so it's the same as everything else up here.

  • We're simply printing this out yellow.

  • Then again, right below that we have the links like we had before else So basically, if the temperature is anything other than what's about what's what we've talked about before.

  • So then what we're gonna do is basically it's a good temperature.

  • Then we're going to print out the color green.

  • Everything else is the same draft and then fan on or fan off.

  • They were gonna come down here and we're going to delay for one millisecond.

  • And then this is where that read string very well comes in.

  • So all the way up here, right, we have a string read string variable.

  • So a string variable is basically words s So we have a variable called read String That is a string.

  • So we're gonna come down here, and basically what's going to happen is if Reed Stringed index of and it says, question mark fan on is greater than zero.

  • So basically, if fan on is in that read string, then we're going to do is we're in a digital, right?

  • I n one too high, and I am too, too low.

  • So I and one is the positive.

  • So we're going to set that too high, and then I into is the ground.

  • So we're going to set that toe look.

  • So if fan on.

  • So, basically, if fan honest sent within the Earl, we're going to turn the fan on.

  • We just do a little delay for one millisecond here else.

  • If you read string, that index of is Fan off is greater than zero.

  • So there's fan off.

  • They were in a digital right eye and one low.

  • I am, too.

  • So basically this is going to turn the fan off.

  • Then we're going to delay for one millisecond.

  • So this right here, this is what's going to be you.

  • So it's going to be reading.

  • So it's going be looking.

  • When you click on that link, that link will show up in the Web browsers, part of Earl, and then you can.

  • Then what is looking for is if it says if fan on is there, then it will turn the fan on the fan off is there that will turn the fans off?

  • Then what we're going to do Pass.

  • That is we're gonna read string, and we're going to set it to nothing.

  • So double quotation marks, double quotation mark that's going said it to nothing just to clear that out, they were going to delay for one millisecond and then we're going to stop the client were a serial dot print line client disconnected.

  • So this is what's going on here.

  • The big new complicated thing that we have is these particular links.

  • When you click on the link, then that will be part of the U.

  • R L that you are.

  • L will be parsed again.

  • That's what's happening here.

  • Read String the index of If there is this within the reach string, then we'll turn the fan on.

  • If this is within the red string, then it will turn on the fan off so that all we have to do is we have to upload this.

  • Then we'll open the Web browser and I'll show you how this works.

  • Okay, so I've uploaded the code to the yard.

  • We know, you know, with WiFi.

  • Now we can go over to safari and take a look, and we can see that it's we have the temperature readout 73.84 That's in really a large numbers.

  • Then below that, we have turned on fan and turn off fan.

  • You can see about every five seconds.

  • This thing is refreshing.

  • So if I put my finger on the temperature sensor.

  • We will then see the temperature go up.

  • So 74 now?

  • Oh, no, it's 85.26 So if you just looking at that, you go.

  • I think I should turn the fan on.

  • I just simply go down here to this link and I could turn the fan on and the fan is gonna turn on.

  • There we go.

  • There s o got the fan and now the fan is spinning and it's speeding up a little bit of re fresh air.

  • And so now it's trying to cool down our environment.

  • Then once the temperature gets down below a certain level, all I have to do is I can go over here no refresh, and I can turn off the fan.

  • And then, as you can see, the fan turns off.

  • So if I click on turn on Fan, the fan turns on courses.

  • Cause me a little problems right now because I'm doing a video.

  • But that's where that's where we're working 10 minutes ago on.

  • Then again, once the environment cools down, I go over here and click turn often.

  • And so this way we have a temperature notification system and were able to a manually turn on and turn off electrical device, such as a family.

  • So that's all there is to this particular project, using an l 298 and module on Arduino.

  • You know, with WiFi, an analog temperature sensor, you're able to create something that's relatively useful.

  • Now, please understand.

  • I know when I was showing you the demonstration of this project, he was acting a bit quirky.

  • One of the reasons for that is because I have to configure the project in a way that works well visually for you folks to see what's going on again.

  • Like with the auto update for the temperature sensor.

  • I set that to every five seconds so you can see rather quickly the temperature going up in the temperature's going down.

  • The problem is, is when you do something like auto, refresh a Web page every five seconds, you can run into some quirks, just functionally with how stable that ISS.

  • So what I would say with this particular project is this is definitely not a project.

  • I would just copy, paste and shove into a production environment.

  • Whatmore in here, I want you to understand the concept and then go through and play with the code.

  • Play with the settings again, Let's say with that auto refresh.

  • Maybe put that out to 30 seconds.

  • Or maybe put that out to a minute, change some things around to find out what actually works stable Lee for you again, that's an important thing.

  • To understand in the real world is not just about making something work.

  • Once it's about having to be stable and worked consistently.

  • The project that I'm showing you today, it's great for the lab.

  • It did.

  • It demonstrates a lot of things for the lab.

  • Again, If I was gonna be putting this into the real world, I would probably do it in a different way.

  • But the main thing I'm when you have to understand is that you're able to get to gain information from a censor.

  • Your ableto output that to an HTML page that's auto refreshing for you.

  • And then you're able to trigger physical events.

  • That's the main thing to take away from this video again, actually building that in the real world, I would probably do it in a bit of a different fashion.

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