Hello, friends.
Today I will tell you how to interface IR sensor.
Or you can say infrared sensor with Arduino.
Using Python programming for that purpose.
I over here, this is my infrared sensor that is connected to the this.
It will this is a module.
In this case, I just use its digital output pin.
I just connect it to the PIN number seven of my Arduino and I just connect positive pin.
Or you can say VCC of my IR sensor to the five volt and ground to the ground.
So now just move to the software part over here.
Just import Arduino library
then.
Import.
Then import time.
After this set up the board just take a variable called.
I already know.
Just set up the baud rate for Arduino.
It is 9600.
Then hold equal to eight.
Call.
Now, in this case, I'm just using digital pin to acquire the signal because I are sensor.
We can use IR sensor for object detection.
So when object is present in front of your IR sensor, it will generate a signal.
Otherwise it will go to sleep.
So you can use Arduino digital pin or analog pin.
Okay, so right now I'm just using digital pin.
I will tell you both ways.
So here just board dot pin mode.
And as you say, one thing and it is an input pin.
Right now.
So now I just use while loop while true.
Inside this.
I just use a variable I sensor that is equal to your board to read.
Crystal Reed.
And the pin number is seven.
Now you just print this value.
Print this value.
Now, I just put some time delay.
So my time delay, let's say it is 0.2 seconds.
Save it.
Run it.
You can check the results.
Of sensor output, it is placing 000.
And when I just place my hand in front of your sensor.
It is sending one signal.
As you see on the i r module also glow.
So this is how you can use your sensor.
With the help of python programming or how you acquire signal.
Oh.
Yes, sir.
This is the digital way.
Now I just go to the analog way.
So for analog way, I just use this pin for I just change this pin from digital pin seven to a zero.
Or you can say right now I'm just using a one.
So now check.
Let's check what happened.
So I just stop it.
So for analog read, I'm just using I'm just importing Arduino time.
Then you just change this because I'm just using analog pin.
So R is equal to board over here.
Analog read in case of.
In case of digital, I just use analog read.
Just put the pin number.
The pin is 1A1 I'm using.
In the case of i r sensor, it will generate around 3.67V.
When signal is there, when object is not there, in that case it will generate zero.
So I'm just again changing this voltage.
So I over here I'm just using the symbol i r r and that i r r is equal to i r into.
Five divided by 1024.
Let's check what happened.
So over here, I'm just using this variable control s save it and run it.
Let's check what happened to it.
It is placing zero zero and now it is generating 3.64003.64.
So this is how you can use air sensor with the help of analog pen also.
In this case, I'm just.
Telling you about.
I told you about how to acquire using digital twin.
How to acquire using analog twin.
Now I'm just change this formula.
If I'm just not, place it over here.
Let's check what happened to it.
So I will directly again run it.
Let's check what happened.
It will generate 000.
And when I place my hand over here, it will generate seven, four, five, 745, because the maximum
range is if five volt is there, it will generate 1024 and right now it is 3.66V.
So now it is generating 7.45.
So this is how you can acquire signal from Iot sensor.
Thank you.