EG254S: IoT System Project - Sensors Sensors

HC-SR04 Ultrasonic Sensor

 (Adapted from: refer to references below)

HC-SR04 ultrasonic sensor provides a very low-cost and easy method of distance measurement. It measures distance using sonar, an ultrasonic (well above human hearing) pulse is transmitted from the unit and distance-to-target is determined by measuring the time required for the echo return. Output from the sensor is a variable-width pulse that corresponds to the distance-to-target.

Ultrasonic sensors are easy to configure and, when combined with other sensors, enable very useful data to be provided about the Rat Bait Station’s environment.

Overview

HC-SR04 distance sensor is commonly used with both microcontroller and microprocessor platforms like Arduino, ARM, PIC, Raspberry Pie etc. The following guide is universal since it has to be followed irrespective of the type of computational device used.

An onboard 2.54mm pitch pin header allows the sensor to be plugged into a solderless breadboard.

Features:

Luckily, the NYP provided ultrasonic sensor is the second generation of the popular HC-SR04 Low Cost Ultrasonic Sensor. Unlike the first generation HC-SR04 that can only operate between 4.8V to 5V DC, this new version has much wider input voltage range, allowing it to work with ESP8266 controller which operates on 3.3V.

Ultrasonic Sensor Pin Configuration

Pin Number

Pin Name

Description

1

Vcc (Power)

The Vcc pin powers the sensor, typically with +5V

2

Trig (Trigger)

Trigger pin is an Input pin. This pin must be kept high for 10us to initialize measurement by sending ultrasonic wave.

3

Echo (Receive)

Echo pin is an Output pin. This pin goes high for a period of time which will be equal to the time taken for the ultrasonic wave to return back to the sensor.

4

Gnd (Ground)

This pin is connected to the Ground of the system.

 

How Does it Work?

The ultrasonic sensor uses sonar to determine the distance to an object. Here’s what happens:

  1. the transmitter (trig pin) sends a signal: a high-frequency sound
  2. when the signal finds an object, it is reflected and
  3. the transmitter (echo pin) receives it.

It emits an ultrasound at 40 000 Hz which travels through the air and if there is an object or obstacle on its path It will bounce back to the module. Considering the travel time and the speed of the sound you can calculate the distance.

https://i2.wp.com/randomnerdtutorials.com/wp-content/uploads/2013/11/How-ultrasonic-sensor-works.jpg?w=700&ssl=1

In order to generate the ultrasound, you need to set the Trig on a High State for 10 µs. That will send out an 8-cycle sonic burst which will travel at the speed sound and it will be received in the Echo pin. The Echo pin will output the time in microseconds the sound wave travelled.

HC-SR04 ultrsonic sensor: precision with a low cost

The time between the transmission and reception of the signal allows us to know the distance to an object. This is possible because we know the sound’s velocity in the air. The sensor works with the simple primary school formula that

Distance = Speed × Time

Now, we can calculate the distance using the above formulae, since we know the Speed and Time. Using the Ultrasonic wave we know the universal speed of ultrasonic wave at room conditions which is 330m/s. The circuitry inbuilt on the module will calculate the time taken for the ultrasonic wave to come back and turns on the echo pin high for that same particular amount of time, this way we can also know the time taken. Now simply calculate the distance using a microcontroller or microprocessor.

 

References:

https://www.sgbotic.com/index.php?dispatch=products.view&product_id=1713

https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/

https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/