B1 中級 11 分類 收藏
開始影片後,點擊或框選字幕可以立即查詢單字
字庫載入中…
回報字幕錯誤
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.
提示:點選文章或是影片下面的字幕單字,可以直接快速翻譯喔!

載入中…

Arduino - IR Sensor Analog Output

11 分類 收藏
林宜悉 發佈於 2020 年 3 月 27 日
看更多推薦影片
  1. 1. 單字查詢

    在字幕上選取單字即可即時查詢單字喔!

  2. 2. 單句重複播放

    可重複聽取一句單句,加強聽力!

  3. 3. 使用快速鍵

    使用影片快速鍵,讓學習更有效率!

  4. 4. 關閉語言字幕

    進階版練習可關閉字幕純聽英文哦!

  5. 5. 內嵌播放器

    可以將英文字幕學習播放器內嵌到部落格等地方喔

  6. 6. 展開播放器

    可隱藏右方全文及字典欄位,觀看影片更舒適!

  1. 英文聽力測驗

    挑戰字幕英文聽力測驗!

  1. 點擊展開筆記本讓你看的更舒服

  1. UrbanDictionary 俚語字典整合查詢。一般字典查詢不到你滿意的解譯,不妨使用「俚語字典」,或許會讓你有滿意的答案喔