Hi, Welcome to Arduino Step by Step Course by Robojax
My name is Ahmad Shamshiri Get codes from Robojax.com
this is one of the most basic and simple to use obstacle avoidance sensor with Arduino it is made
of a transmitter which emits infrared light and a receiver which receives infrared light so the
wave goes and heads an object for example this object and the reflection comes back and
is amplified by this operational amplifier and output sets the spin to low when it detects an
obstacle is detected the led will turn on and output will go low there is also a potentiometer
that you can adjust the sensitivity uh with this one so you can change the distance that
that this can react and show the voltage at the output these terminals have been labeled as vcc
this will be connected to five volts the second one is the middle one connected to the ground
and the last one is the output which we will connect we have also two led here this is a power
led when you connect it to the power this will turn on and this is the detect led when it detects
the infrared signal back this light will turn on and also we have signal at the output
depending on your IR application you can bend this
if you need a different angle without this connector it's 39.4 millimeter the length
the width is 14 millimeter
the depth is 6.8 millimeter
here is the wiring diagram that I’ve drawn from the right the vcc is connected to five volts
the middle one is ground I’ve connected it here you can also connect it to any of these two
grounds and then the output is connected to pin eight and here the actual wiring on the device the
right side is connected with the rest red wires to five volts the middle one is orange have been
connected to the ground and the last wire which is the out have been connected to the aid of Arduino
let me now explain the code we are defining pin 8 as a signal pin where the obstacle avoidance will
be connected up and eight inside the setup we define the serial monitor with 9600 board this
is a serial monitor which I’m going to open by clicking at tools and serial monitor and this 9600
body is the value that is must be the same and then we use pin mode signal pin and then we say
should be as an input this is as if I type 8 and input so this will set pin 8 as an input
inside the loop which starts from this point up to here we first use digital read
and we read the signal pin that's pin 8 and the result which will be either high or low
will be stored in the variable called detect and here we check if detectives == low
this module will send low signal when there is an obstacle so we check it if it's equal low then we
print this text or we take an action between this point and this point for example you turn
a motor on to start or to stop if the obstacle is on the way for this case we just type this text
else means otherwise if the obstacle is not there no signal just print all clear
let's open the serial monitors tools serial monitor
and as you can see it shows all clear the reason for that
is because there is enough distance that it does not detect and here I’m bringing my hand closer
as you can see it shows obstacle on the way
if I go away so this cannot be used for four distances this is a distance
eight centimeter as you can see
around six centimeter it shows reaction five point five or six but we can adjust it the sensitivity
so it can show further for example this is now let's put it as 7. now I’m rotating it clockwise
when you see the light make sure to go back a little until it stops
now this if I bring it here so it detects it
now how about if I go further nine centimeters currently I’m at nine centimeters let's check it
now it's nine centimeters
it's an edge as soon as I bring it a little closer
as you can see here now it's at 10 centimeters an hour if I get it closer at nine
it detects the obstacle
as you can see here now it's around
nine at the 6 or 8.5 it detects it but depending on the surface
if the surface is very shiny for example let's try this Arduino box
yeah it works but if I point put my phone with a glassy surface
also it works
let's try this plastic and see if it detects it
that it reduced the distance but still it works even with plastic with clear plastic
but the distance will be reduced it doesn't work at nine centimeter
see here now it's around
9 at the 6s or 8.5 it detects it but depending on the surface let's try this Arduino box
yeah it works but if I point put my phone with a glassy surface
also it works
let's try this plastic and see if it detects it
it reduced the distance but still it works even with plastic with clear plastic
but the distance will be reduced it doesn't work at nine centimeters