Placeholder Image

字幕表 動画を再生する

  • please go to the line the computer guy dot com, in order to view schematics, code and Maur for the projects that you are learning about.

  • Welcome back.

  • So in today's video, I want to show you how to use an infrared proximity sensor using the digital outputs.

  • When you use infrared proximity sensors, you can use them both for digital output or for analog output.

  • When you're doing digital, basically, it's either on or off.

  • You don't get a range of values.

  • When you do analog, you could get a range of values.

  • When you do, digital is either on or off.

  • Either something is close or it's not close.

  • You don't get anything in between.

  • So this could be very valuable, especially when you're building things like autonomous vehicles that are going to be moving around in environments with obstacles.

  • So this is a way basically, you can have the vehicle be able to tell if it gets too close to an object without actually having to bump up against it.

  • So that's what makes these infrared distance sensors a valuable thing to use so that let's go over the workbench.

  • I'll show you the components of this particular project.

  • Then we'll show you how to code it up, put it all together and show you how it all works.

  • So for this project that really are only two major components, of course, we've got the Arduino board we're using, you know, But you could use another word we know board, obviously for project like this.

  • And we have our infrared a proximity sensor.

  • These are the only two major components you need for this project.

  • So we put those two aside, we can take a look how I built this particular project.

  • So again, you can see we have the yard.

  • We know board.

  • Over here we have our infrared sensor.

  • And so what I did is I just kind of mounted this infrared sensor using when he standoffs a couple of nylon screws and nylon nylon nut and put it onto this little plastic thing.

  • And basically, I did that so that I can test how this works, right?

  • So if I plug the infrared sensor into something like a bread board, then when I did that, it would point straight up, and it wouldn't give me a good feel for how the infrared sensor works.

  • in the environment that I wanted.

  • So if I'm gonna be using one of these infrared proximity sensors, I'm generally want to be using it on a vehicle and generally, if it's gonna vehicle than it is going to be position horizontally.

  • So putting onto a little plastic apparatus like this just makes it easier so that hooking it up, it's broke pretty simple.

  • You have a sensor, and then you just have the three wires.

  • So all the way on the right hand side, you have the voltage.

  • You have VCC vcc then goes into the five volt on the Arduino board.

  • The middle pin for this particular sensor is the ground that goes to the ground on the Arduino board and then all the way on the left, that is the out or the signal and that we're going to be putting over onto Digital eight.

  • So this is all you have to do to be able to build this particular project.

  • Let's go over to the code and take a look at how to make this thing work.

  • So here's a code for this project.

  • So all we're going to be doing is we're going to be doing a serial printed, so we're going to printing out the serial monitor.

  • If the infrared sensor detects an object, it will print stop.

  • If it does not detect an object, it will print all clear.

  • That's relatively simple here.

  • The first thing we're going to do is we're going to define the infrared pence of the infrared sensor pen.

  • So we're going to do pound define I R.

  • Is what we're going to be calling the pen, and that is digital pen eight.

  • We're then going to have to create a variable s so that we can check against that in the if else statement.

  • So we're going to create an int variable, and we're going to call that obstacle.

  • So this is what we're going to be testing against in the f l statement, and that's all we do there.

  • We didn't go and we set up the environment.

  • This code is going to run in, so we're going to do the pin mode function so pin mode, I r.

  • And we're going to put that to input.

  • So it's going to be a receiving data from the sensors.

  • We put it to input and then in order to be able to read this from the cereal monitor.

  • We have to start the serial monitor, so serial dot begin 9600.

  • So that's all you have to dio to set up the environment past that.

  • We're then going to go into the loop.

  • And so here's what we're going to do is the variable obstacle were going to say variable obstacle equals the function digital read I are so was going to go to I.

  • R s is going to go to pit eight.

  • It's going to do a digital read of pen eight and whatever the value is that is now gonna be the value for obstacle.

  • Then all we do is we go down here.

  • It seems counterintuitive.

  • That seems kind of weird.

  • But as far as a variable in the infrared is concerned, low means means obstacle.

  • Hi means not obstacle.

  • So you you would think there's an obstacle just in your brain.

  • You think high would be obstacle low will be all clear.

  • And for whatever reason, it's not that way.

  • So basically low means there's an obstacle.

  • High means all clear.

  • So we're gonna do here is we're gonna go say, if obstacle equals.

  • That's a two equal signs to make sure you do double eagles, right?

  • If you do a single equal, it sets the value of the variable.

  • If you do double equals, that's when it says if this is equal to that.

  • So if double equal signs is low, so low, then what we're going to do is where I do serial print line.

  • So it's gonna print this and go to the next line stop.

  • So if it if it detects low, it's when a prince stop else.

  • So anything else there's only two.

  • It's digital.

  • There's only two options here, so either is low or high.

  • So it's something it's it's not low.

  • It's gonna be high.

  • So they were gonna do serial dot print line.

  • All clear.

  • So it'll print stop if there's an obstacle that next line.

  • If there's not an obstacle from all clear, go to the next line.

  • And then for this.

  • I've set this for a delay of 500 milliseconds about half a second, so this is fast enough to see it operate rather quickly, but still slow enough that we can actually perceive what it's doing so that what we're gonna do is we're gonna upload this code to the Arduino and then take a look to see what the results are.

  • So now that we have the code and we have our little project building will be plugging this thing in, we're then going to upload the code and then we can go to tools.

  • You go to serial monitor and we can see what it seems.

  • So as we can see here, it sees all clear.

  • So currently there's nothing in front of the infrared sensor, so it's not detecting anything.

  • As I bring my hand closer and closer and closer, you'll see a servant point and now see something so it tells you to stop.

  • So again.

  • So if you had this on a robot car, some kind of autonomous vehicle, it means that right about the one age mark, this would trigger.

  • And then it would do whatever you were told to do for my hand away.

  • It goes back, bring forward.

  • It says stuff.

  • Now One of the nice things about this particular sensor is it does have the green led.

  • So whenever something is to close, the green led goes off.

  • So this is one of the nice things that you can use for a troubleshooting process.

  • So if you're writing code for the infrared sensors and you're not sure what the problem is, is it The sensor is your code so on and so forth.

  • The nice thing here is you can see that the infrared sensor is working properly.

  • So if your code isn't processing properly, then you need then you know, to go troubleshoot the code.

  • Right?

  • So with the sensor, if if that light wasn't going off, then you may think, Oh, maybe I screwed up on how I wired this thing.

  • Maybe there's a fault with the sensor, that type of thing.

  • Whereas if the green light goes off when it's supposed to, then you know Okay, most likely the sensor is working properly.

  • I need to figure out what's going on with the coat.

  • And so this is what we can see.

  • Basically, how the infrared sensor works now, when I think that you should do again whenever you're using something.

  • A proximity sensor.

  • I talked about this before with like the ultrasonic distance sensor.

  • One of things you should check is basically the different types of angles you can approach the sensor at and when something will be detected.

  • So like one of the problems with ultrasonic distance sensors is that if an object comes at them from a sharp angle like a 45 degree angle, they won't work properly because the signal comes out and it reflects in another direction and doesn't go back the receiver.

  • One of the cool parts about the infrared sensor is that, as you can see, even if you come in at a very steep angle, it's still able to detect that there's an object there.

  • So that's one of the benefits of this type of infrared sensor and one of things you should be thinking about when you look at proximity sensors.

  • So again, if you look at what's an ultrasonic distance sensor, it is much more accurate, and it could be much more refined.

  • But the problem is, if it comes at an object at an angle that's a 45 degree angle.

  • It won't function properly, whereas with his infrared sensor, it's not nearly as accurate.

  • It's not nearly as precise, but you can come at it at all kinds of different angles and will still work how it's supposed to work.

  • So these are some of the things that you should be thinking about whenever you're dealing with any kind of proximity sensors.

  • So that's all there is to using an infrared proximity sensor with the digital output to detect.

  • If something has come too close to your particular Arduino project again, this is very valuable with things such as autonomous vehicles, basically, to make sure that the vehicle isn't bumping into things as it goes around.

  • Whenever you're thinking about Korean autonomous vehicle, you're going to need to think about creating an array of sensors.

  • Normally, when you see these vehicles, there's an array of sensors, so you may have an ultrasonic distance sensor and that tries to detect a longer distance and tries to give the vehicle Maur information so we can try to pre plan what its routes going to be.

  • You'll have a bumper sensor so right, obviously, if the vehicle you know, if if if all the other sensors fail and the vehicle bumps up against something, you're gonna want to have a bumper sensor s so that when it physically makes contact with something, it is able to react to it, but a way that you can have the vehicle react when it gets close to an object, but not so close that it actually hits.

  • The object is you can use one of these infrared, distant sensors.

  • And then again, when an object gets too close, it just sends a signal and then your Arduino project in the process the signal and determine what to do next, eh?

  • So that's how you use when these infrared sensors is just very, very simple.

  • If something's faraway, nothing's detected if something gets too close than the vehicle can react, so that's all there is to it.

  • As always, I enjoy doing this video and look for anything on the next one.

please go to the line the computer guy dot com, in order to view schematics, code and Maur for the projects that you are learning about.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

ArduinoでのIRセンサーデジタル出力 (IR Sensor Digital Output on Arduino)

  • 11 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語