Hi, Welcome to Arduino Step by Step Course by Robojax
My Name is Ahmad Shamshiri
this is infrared obstacle avoidance sensor this can be attached to any robotic
devices such as smart car robotic arm and it emits infrared light an infrared beam will hit
the object return back and the reflection will be detected as a signal at the output
and this is quite large but it has its own application it comes as a screw type so
you can create a whole the size of this insert it and then tighten this and it has three wires here
at this end we have a screw for a potentiometer which you can adjust the sensitivity and there is
also an led when it detects an obstacle this will turn on and at the top you will just see these two
lenses that underneath there is transmitter and receiver of infrared uh we have three wires
the brown is the five volts a signal out where it will be detected and blue is this background
let me explain now the code let me explain now the code
we will define pin two for the sensor we will connect the signal pin to this pin and we call
it sensor and there is an action pin extra pin I just put it in case if you want to use it when it
detects uh obstacle you do something and send high signal to pin nine it can be motor it can be light
buzzer whatever so this pin will go high and inside the setup we defined this serial monitor
with 9600 baht we use pin mode sensor input pull up and put sensor needs input pull up
I have explained this in the early lectures and then we use pin mode action this is pin
nine as an output and here we use digital read sensor we read the sensor pin and the result
which is either high or low high is 1 low is 0 will be stored in l integer l and here we check
if l is == 0 I could also type low both of these are the same check if low means obstacle is
detected then we print the text it says obstacle detected and then also we do digital right
action panel which is nine we will set it high and here is the action that you do between these
opening and closing parentheses whatever you do will be here if you're controlling a motor to
be stopped or started because this piece can be used also to start something when it detects an
obstacle something should start and else otherwise if there is no obstacle also you can take an
action here and we just put here all clear and also we send the pin which was high we send it
and set it to low and there is 500 millisecond delay and the loop continues like that
here is the wiring diagram the brown have been connected to 5 volts the blue have
been connected to ground and the black which is a signal have been connected to pin two
from pin nine I’ve put this led this could be battery relay motor whatever you want to control
uh this pin 9 have been connected to anode of led and then the cathode have been connected to
one kilo ohm which is connected to the ground and when the obstacle is detected this led will turn
on here is a wiring brown have been connected to five volts blue have been connected to the ground
and then the black have been connected to pin two from pin nine from this pin
I have a wire which has gone to this led the anode the longer pin is on this side and the cathode the
shorter pin is on the other side through one kilo ohm that has been connected to the ground
and here is the demand here if I point it this is the actual point if I point it down
you will see that it is detecting an obstacle
but the length you have to know how far I’ve been here demonstration
as you can see when I bring my hand we will see that obstacle detected and also the led
will turn on now I’ve put this box at around 10 centimeter from here and as you can see
the light is off and I’m trying to adjust the potentiometer now I’m going clockwise rotating
remember this is multi-term potentiometer so you will not see immediate effects so
I’m trying rotating it clockwise
now the light started blinking and now as soon as you see the light turns on slowly turn it back
counterclockwise until it just barely turns off
now exactly I’m at the edge when I go to the left or right
now it works with 10 centimeter a little less than 10 centimeters so if I get closer you see
it can work up to 10 centimeter now
let's see if we can do it
15 centimeters
I’m rotating this clockwise
I wrote it like full rotation or two
now
this seems now almost 14 centimeters yes we are getting up to 14 centimeters but
remember this depends on the type of surface and shiny surfaces or
different surfaces will have different reflection and as a result
the distance that this can work differs that detects the signal also this light turns on
you see I’m pointing it below the disc
and the light is off if I bring my finger you will see the light is on