Hi, welcome to Robojax. In this video I'm going to show you how we can use
this infrared emitter and receiver as the obstacle avoidance this can be used
for educational purpose to learn the meaning of obstacle avoidance with
Arduino so this is the module easy to use and very cheap when the module the
module has three pins this is VCC this is ground and that's the output and we
also have two LEDs here this LED is for power when you connect it to the power
it will be always on and this led is when it detects an obstacle we have also
have a potentiometer (variable resistor) that you can rotate and change the detection
distance for example if you rotated on one direction it will detect obstacle in short distance
but if you rotate it to the other direction it will go to the
maximum of 95 or 100 millimeter which is known 9.5cm this cannot
detect an object longer than that or in a farther distance. so this is the
emitter which emits infrared ray and when it hits the object it just comes
back and this is the infrared receiver which receives it and there is a simple
operation amplifier or op-amp that can just detect the infrared and turn this
light on but the output will be will be LOW when it detects an object but when
there is nothing here no obstacle so this sends the signal and no infrared
comes because there is no reflection the output will be HIGH(5V) but when there is an
obstacle in front of it here then it goes and comes back and if
detects it then this LED will be ON but this output will be LOW (zero volt) so we are
detecting LOW as an obstacle and HIGH as clear or no obstacle
the sensor has 2 LEDS. 1 LED is for the power and there is another LED which
when if when it detects an obstacle the this LED will turn on so now let me show
you I'm putting this say this notebook and the light is on because it has
detected something so how it works is that the infrared signal goes and
reflects back and this measure it. so with this potentiometer we are
actually changing the sensitivity of this one (the receiver) so how a strong signal it needs
the further the object the weaker the signal that receives so we can adjust it
that it means for example if you want to decrease the distance you are decreasing
the sensitivity and it needs strong and signal for example at this distance it
works very well so now let me increase the distance as you can see if spirit
works the light is on which means there is an obstacle I am going farther and
now this is off so if I put my ruler here this from here to here is 95
millimeter so it's about 100 millimeter or 10 centimeter as we
if you want to know it in terms of inch it's about 3 and a half inch
just 3 and 3/4 of an inch so almost 4 inch so if I get farther it turns off
now this is able to detect this object but if you
want to reduce it and make this not to measure this distance or any farther so
we just rotate this and counterclockwise I'm just rotating it the other way
so now as soon as I get away a little the light is off and now as you can see
it's almost 2 inch or three inch I was 7.5 centimeter I just
reduce the distance so we can reduce it significantly and then I'm
just rotating it to the the left
further so now this needs object to be more closer if you want to reduce the distance further
you can do so so we can reduce it but the maximum that this one can measure is
10 centimeters this is about the distance that this can do so slowly turn
it clockwise turn it to the right until the light is on
so another light is ON it doesn't detect and here it detects so this way you can
reduce and increase the distance with this potentiometer so da when it
detects on an obstacle this LED is on but the output actually goes off so when
there is nothing the output is HIGH or there is a 5 volts at the output this
last 10 so this pin will always have 5 volts when there is no obstacle when
there is an obstacle now this is on the output is zero or LOW. now let me explain the
code this line inside the setup is for displaying on the serial monitor 9600
baud and then we set pin 8 as an input and then inside the loop which is the
main one we read the pin 8 with digitalRead ( 8 so that is the status of
pin 8 and the result is stored in the variable integer "detect" and here we say
if (detec is equal equal, it means compare this to this if it's
low then the obstacle is detected so we say " obstacle on the way" else otherwise
we say "all clear" and then we wait 300 millisecond so this is almost three
times a second so it just continues like that
so let me upload the code and then open the serial monitor here and see on the
screen it shows all clear and there is no obstacle on the way so if I measure
this so this is about 10 centimeters so let me bring an object you see when it
detects an object this obstacle is on the way
this text when it turns off so obstacle on the way
the way you can detect an obstacle. now what you can do is when the obstacle is
detected you can also control a Servo Motor so when you say have
detected equal low which means obstacle detected so here you can just give a
command to a Servo Motor to do something and if a motor is stopped if a motor is
running you can stop it or you can turn on something else so whatever you want
to do it will be between this F or if there is no obstacle you can do
something here so the action will be here in the who I will create another
video to show how this one can control a servo to rotate at a certain angle and
that can be connected to a steering wheel so it can go left or right.
as I was looking to find out the diagram for this module I came across so
many diagrams for example this one this is completely wrong for example this one
the output of this op-amp is high if this is high then the LED will be on the
obstacle detected that's correct but this one is high which is which contrary
to the module the module is always low when this is high so this was one
diagram and there is another diagram circulating somebody shows this one this
is also incorrect so the code for this project will be available by clicking at
a link of the description below and also you can go directly to
www.Robojax.com/learn/arduino thank you for watching please thumb up 👍
the video please share it and also subscribe so you can get updates of my
upcoming videos
Subtitle typed and corrected by Ahmad Shamshiri on Mar 10, 2020 .
I created this to help you. The least you can do for me is not to skip the ads and also 👍 the video and subscribe.
It is appreciated.
you