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 this video, I'm going to show you how to read from an in disparate obstacle avoidance sensor to an analog port on your Arduino board.

  • So I've done a video before showing you how to read using a digital port.

  • It is, you know, port will simply either give you a low or high value.

  • If you use the analog port, it will give you a number at the end of the day.

  • It doesn't actually give you that much Maur functionality, but it's good to realize that there is a different way to be able to read from the infrared sensor.

  • And in a particular project.

  • You may find this to be a more valuable way to read from one of these things.

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

  • I can show you the components will be needed for this particular lab.

  • Show you the code, and we'll put it all together.

  • So for this particular lab, the only important components are again.

  • You're arguing aboard.

  • We're using the art we know, you know, board here and infrared, a proximity sensor.

  • So these air simply the major components that will need then to put all of this together.

  • Put this aside.

  • Basically, you can see what I've created here.

  • Now what I have done is I have screwed the infrared sensor to a little bass.

  • Guess so I can put it in a horizontal plane That makes it a little easier to interact with, since it is supposed be an obstacle avoidance sensor.

  • But other than that, all we need is the jumper wires here.

  • So with this, what we're going to Dio is the right hand side.

  • So this is positive power.

  • So this is going to be going to the five Volt on the Arduino board.

  • The middle wire is for ground that will go to the ground connection on the Arduino board and then for the sensor wire for this particular project, this will be going to a zero sense be going to the analog side.

  • Do you remember the digital side?

  • His long decides along the right hand side here.

  • The analog side is the smaller section, and that's below the power connectors were gonna be plugging this into a zero on the analog side, and that's all there is toe wiring this thing up.

  • So let's go take a look at the code.

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

  • The first thing that we need to do is we need to define the infrared sensor pen so we're going to do pound, define I R.

  • And that will go to a zero pen a zero.

  • Remember, whenever you're dealing with the Arduino board Digital pence, you simply put the number you're dealing with an analog pin.

  • You put the A in front of a zero a one a two so on and so forth.

  • The next thing that we need to do is we need to create a variable for reading.

  • So basically, when we take a reading from the infrared sensor, we need to put you put that value somewhere, So we're going to create an int variable cold reading.

  • Then all we're going to do in order to set up the environment as we're going to simply do serial dot begin 9600.

  • So this starts the service for the serial monitor.

  • We don't need to do anything else again.

  • Since it's an analog pin, we don't have to set the pin mode to input and alone will always be input.

  • Then we're gonna go down here to the loop.

  • So this is loop will keep looping, loping, looping.

  • So all we're going to do here is we're going to take that variable reading, and we're gonna make the value of that variable reading analog greed function Whatever is coming in through the I.

  • R.

  • Penn.

  • So analog Reed is a function that will read from the i.

  • R.

  • Penn.

  • And then whatever that value is that will then be transferred over to the reading variable.

  • Then all we're going to do is their own new serial dot print line reading.

  • So whatever the value of reading is, then it will go to the next line, and then we're gonna delay for 500 milliseconds or approximately half a second s.

  • So that gives us an ability to read what's going up.

  • So with that, let's go over, plug all this in and see how it works.

  • So now we're going to plug all this in, plug this in.

  • We're then going to upload once it's finished uploading.

  • You can go to tools we could go to serial monitor and now we get the number from this.

  • So basically there's nothing now currently in front of the infrared sensor CD in the number of 1000 23.

  • If you bring something closer, closer, closer, closer.

  • Okay, now you're getting a number of 16 or 17.

  • So basically, you know, if it's if it's above its above 16 or 17 then it's farther away than I can see.

  • If it's a 16 or 17 then it is something that it can see, and this basically just gives you a number to work with.

  • So if you're using the infrared sensor again, you can connect it either to the digital port where the analog poor.

  • If you attach it to the digital poor, then you're going to simply be looking for high or low.

  • If for some reason, though you want to be working with a number, this is a way that you could basically doing if else statement based off of a number.

  • So that's really all there is to using an infrared obstacle avoidance sensor using the analog port on the Arduino weather again Whether you use digital or analog probably really doesn't matter for most projects, but this does give you another option.

  • That works perfectly well.

  • So that's all there is for taking their reading from the infrared obstacle avoidance sensor and reading it to an analog port on the Arduino board at the end of the day, more or less get the same result that you do.

  • If you use a digital pin for this, the difference being is that you get an actual number, and maybe that might be important.

  • Maybe you need to do something with a number within this sketch that you're creating for.

  • Or do we know if you need a multiple applied by something or divided by something or something like that?

  • So basically, being able to get a number that might actually be valuable for, you know, at the end of the day, it's yeah, same same, but different.

  • Basically, if you take the digital reading, you get a high or low.

  • If you take the analog reading, you're more or less.

  • Get that one number when it's close to something 15 16 17 and it's far away like 1000 28 something like that so again, at the end of the game, or or less, you're getting the same results as if you use a digital reading.

  • But for some reason you may need a number, and so this gives you an option.

  • And again, whenever your code in your building projects a lot of times simply having an option, you may not use it very often.

  • You may use it once in your career, but simply having that option available may be a lifesaver in a particular instance.

  • So that's all there is to it.

  • As always, I enjoy doing this video, and I look forward to see what 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, welcome back.

字幕與單字

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

B1 中級

Arduino - IR傳感器模擬輸出 (Arduino - IR Sensor Analog Output)

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