Ultrasonic sensors

Ultrasonic sensors are used for noncontact proximity, object detection, and distance measurement. As the name suggests, these sensors use ultrasonic waves as a source to detect the object and its distance. The sensor measures the distance to an object by calculating the time between emission and reception of ultrasonic waves. Ultrasonic waves are very accurate over a short distance and do not create disturbances as they are inaudible to human ears.

The sensor has both an ultrasonic transmitter and receiver. The sensor works on the same principle as that of sonar/radar, which evaluates the presence of an object by listening to the echo of sound waves or radio waves reflected from the object. The sensor emits a burst of high frequency, short-wavelength ultrasonic rays, which when echoed back from the object are received at the sensor. The time difference between sending and receiving the echo is used to calculate the distance of the object from the source (sensor). Refer to Figure 6.10 to understand the basic setup and working of an ultrasonic sensor:

Figure 6.10

In our use case, we make use of the readily available ultrasonic sensor module HC-SR04, as shown in Figure 6.11:

Figure 6.11

As shown in the preceding figure, the HC-SR04 ultrasonic sensor module has four pin outs, which are explained as follows:

  • Vcc: Here we apply a 5V input voltage that will power the sensor.
  • Trig: A high signal (3.3V TTL) is applied at Trig, which will cause the sensor to emit high-frequency ultrasonic waves.
  • Echo: At this terminal, we read the output of the sensor. When we apply the high signal at pin Trig, the ultrasonic waves are emitted from the transmitter and the Echo pin goes high and remains high until we receive the ultrasonic waves at the receiver, which is reflected/echoed back after bouncing off from an object/obstruction.
  • GND: This pin is used to ground the sensor.

Let's understand the workings of the ultrasonic sensor in more detail with the help of a timing diagram as shown in Figure 6.12:

Figure 6.12

When we apply a high signal for 10 microseconds on the Trigger (Trig Pin), it causes the transmitter to emit a burst of eight high-frequency (40 KHz) pulses of ultrasonic waves. The output at the Echo pin goes high and when the ultrasonic waves return to the receiver of the sensor, the output at the Echo pin goes low again. We log the time stamps when the output at the Echo pins go from low to high and high to low and calculate the difference between both timestamps. This time difference is proportional to the distance between the sensor and object from which the ultrasonic waves are reflected back.

Let's calculate the exact distance of the object from the sensor using the following formula:

The speed of sound waves (ultrasonic) = 330 m/s.

The distance traveled by waves = 2 x d. The total distance traveled by waves is twice the distance between the sensor and the object because waves travel twice—once when transmitted from the sensor and next when reflected from the object (refer to Figure 6.10):

Time = (time at which the ultrasonic waves are received - the start time of the ultrasonic waves)

By using the preceding formula and information, we can easily calculate the value of d (distance). In our use case, we are building a security surveillance system, where we can put this sensor at different places such as gates and lockers and we can design the rest of the circuit in such a way that, when any person or object comes within certain distance of the gate or locker, then it can raise an alarm.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.104.120