Hello everyone, it’s Frenoy here and today, we are going to look at this ultrasonic sensor
that can be used for navigation.
In the last robotics video, we looked at using IR sensors for object detection. I have two
such modules with me which contain an IR LED and a TSOP module. These can be used by placing
them around the rover and you would need to use multiple modules for navigation. IR sensors
like these are mainly indented to be used for close proximity as they can only detect
obstacles between 5 -10cms. This is good enough for some applications, but if you are looking
for something that has better range then you would want to use an ultrasonic sensor like
this one. It can detect objects that are between 2cm – 400cm which is pretty useful in many
cases.
If you compare the cost, then both of them are approximately the same – depending on
where you buy from. It is very common to use a stepper motor to rotate the ultrasonic sensor,
so that you can get a better idea of the surrounding. We will learn how to use the ultrasonic sensor
in this video and we use a stepper motor along with it once we actually add it to the rover.
So let’s dive in.
This is what the module looks like and as you can see we have a couple of ICs on one
side, along with an ultrasonic transmitter, receiver and crystal on the other side. So
how does it work? Well, an ultrasonic sensor uses something called echolocation to get
an idea of its surroundings. This is similar to what bats use for navigation. At a very
basic level, all it is doing is transmitting a sound wave which bounces off the surroundings
and is then detected by the receiver. This module processes the signal that is received
an it gives us an output corresponding to this signal. The module uses a frequency which
is around 40KHz, and this is in the ultrasonic range which means that we humans cannot hear
it.
The module has 4 pins, VCC and ground are for power and it runs on 5V. Next we have
the trigger and echo pins. The module waits for a signal on the trigger pin, before it
sends out the signal. The trigger has to held high for at least 10uS for the module to generate
the signal. The module will then send out the signal which will be in the form of 8,
40KHz pulses. The reflected signal that is received, will then be processed and the module
will output a signal on the echo pin. The pulse width of this signal represents the
time in microseconds that the signal took to return to the module.
Obtaining the distance from this signal is extremely easy. We know that distance is nothing
but the speed into time. For our purposes, the speed of sound is constant at 340m/s or
0.034cm/uS. The module will give us the time taken and using that we can obtain the distance.
The only thing we need to consider further is that the signal has to travel to the object
and then back, which means that the actual distance between the object and the module
is just half the distance. This is why, we divide the output here by 2 to give us the
distance between the module and the object.
Now that we know how this module works, we can connect it to an Arduino and write a sketch
to use it. Here’s what the test sketch looks like: Pin D7 is the trigger pin and D8 is
the echo. We set these up and enable the serial port. We set the trigger pin HIGH, wait for
10uS and then take it LOW to give us the trigger pulse. We then use the pulseIn function to
obtain the pulse width of the echo that is received. The term HIGH indicates that we
are interested in the pulse duration when the signal is HIGH. Once we obtain the duration,
we can calculate the distance and print that to the serial terminal. I’m going to upload
this code so that we can test it.
Here’s what the connection diagram looks like and everything is pretty straight forward.
I have connected it on a breadboard like this and this is what the output waveforms look
like. As you can see the pulse durations are as per what we have discussed earlier. The
serial output displays the distance and it varies as I move the object away from the
sensor.
And that is how easy it is to use an ultrasonic sensor like this one. We will cover the remaining
sensors in future videos and we will then add them all to the rover and control it.
Please consider subscribing, if you haven’t already. Thank you for watching and I will
see you in the next one.