in this lecture we are going to learn how we can use this laser transmitter that transmits
laser beam and this is the laser receiver that receives and detects the laser beam
and will send the signals which we will detect using Arduino one way that this can be used as
we have seen it in some movies is that this sends continuous signal the laser is hitting this and we
are detecting that the signal has been reached here and the establishment of the signal means
no obstacle and when an obstacle or something comes and cuts the laser beam it will be detected
with Arduino and we take action for example we turn on alarm or maybe turn on lights or send
a picture or SMS whatever action you want to take based on the obstacle existence between the two
transmitter receiver and the laser beam can be viewed when an object or something comes
in front of it you will be able to see the laser beam this can be used as a counter
every time the signal is blocked we can count and increment the number
the transmitter this is the laser beam transmitter and they made it as a module
and they have provided three pins here this is the negative or ground this is the signal we are not
going to send some specific signal we just turn it on continuously so this can be used as a counter
or as an obstacle avoidance so we will be using only this left and right pin and the middle pin
will not be used and this is the receiver the receiver however has ground pin and vcc so
ground is on that side vcc is on this side and the middle pin is an output and it continuously
needs five volts to operate and when the laser beam heads this lens here this is the receiver
this output pin will go high and we can detect it using Arduino to take action
when you purchase this module you will receive it something like this
and when you are inserting it pay attention to this and on this side this side is flat
and we have a lens on this side the lens side must be inserted make sure that
this is the flat side and the lens must be facing the pins or inside the module
here is the wiring diagram that I have drawn using first thing the transmitter have been
connected from this side which has negative this has been connected to the ground using green wire
and the s or signal pin which is on the left have been connected using a blue wire
to pin 13. the receiver on the right side this is vcc this has been connected to 5 volts
on the left side this has been connected to the ground
the metal pin which is the output from this transmitter have been connected to pin 2 where
we will read it at this pin and here is the wiring on the Arduino the green wire from the
right from the negative have been connected to the ground of Arduino this ground that we have in here
and the blue pin the signal have been connected to pin 13
and here for the receiver vcc from this using white wire have been connected to 5 volts
on the left the ground have been connected via this pink pin
to this ground and the middle wire which is the output I’ve been connected using the grey wire 2.2
let me explain now the code we define at a pin 2
as detect pin and we define pin 13 for transmitter this is the pin that transmitter will receive
the power and also we are defining action pin pin 8 this pin 8 can be connected to a relay
which we have explained so many times in other videos or it can be connected to a
light or bother whatever you want in this case I’m going to connect it to a buzzer inside the setup
we initialize the serial monitor with 9600 ball this is the rate that when you open the serial
monitor it must match this is just printing the text on the screen and then we define the text pin
detect transmit action three of those here using the pin mode as input detect is an input action
is an output and transmit is also an output after this line we use digitalwrite and for the transmit
we set it high so this continuously gives power to the transmitter inside the loop using digital read
we read the detect pin and the result of that detection value will be stored in the detected
variable of type integer and here we use if statement and check that detected if it is equal
low we've used two equal sign to compare these two and low means when an obstacle blocks it and there
is no laser we will detect it and then we send the action pin high this can be connected to a buzzer
also we print this on the screen obstacle detected if this is not low which means the laser beam is
continuously shining and the pin is high then we use else because if it's not low it will be
high else then we send the buzzer to low so the buzzer is off and also we print this clear
on the screen and we wait 200 milliseconds and continuously read this using this loop
I pointed the transmitter towards this receiver at this point but still it's off so I have to
make sure that it is shining to this and as you can see it shows uh obstacle detected as the
detected mean that the signal is not reaching so I have to make sure that we read here clear
now it says clear and I have to put some something underneath of this to lift this up
you can see at the moment it shows clear the reason for that is the laser beam is hitting here
and the reflection is being detected and this is problematic and make sure that
you point it directly to the device not from the reflection after working and trying to adjust it
now it's perfectly hitting this receiver now if any objects or anything comes in between
as soon as you block it you will see that it says obstacle detected
I put this breadboard it says detected and clear and detected
and that's the laser beam that is hitting here
this can work for very long distance maybe hundreds of meters
but the problem is that the further you put these transmitter and receiver apart
the harder will be pointing the beam to the receiver
now I’m connecting this five volts batter on this side this will be connected to pin eight
and this negative side will be connected to the ground now because the beam is
not aligned the buzzer is on so I have to align it and make sure that it is not on
I was able to align it now as you can see the beam is shining here
and if I block the beam using a simple paper
alarm will turn on if you want to delay the alarm detected and this should stay on for
longer periods just add 5000 milliseconds for example to keep this running when obstacle
is detected now if I create an obstacle this will be on for five seconds before it goes off