null

Unlock a 3% Reward on Every Order!

Same Day Shipping if Order Placed by 2pm

GST Invoice on All Orders

A beginner’s guide to Ultrasonic Sensing Technology

Published by Abhishek Singh on 23rd Jun 2019

Introduction:

In this article we will discuss about the ultrasonic sensor, their wide spread applications in industries and their use for commercial purposes. The article focuses on the technology behind the ultrasonic sensors, and helps embedded developers in choosing the right type of ultrasonic sensor with its detailed specifications. Finally the implementation of the sensors by using the Arduino board will be discussed at the end of this article.

Boom of Sensing Technology:

With the advent of sensing technology, the security and assistance needed in our daily life is greatly enhanced by highly sophisticated sensors. Sensing systems not only secure our important protocols but also provide real time assistance.

image004-1-.jpg

Consider a case in which an amateur driver, Ravi finds trouble in parking his car in narrow places, which is always the case in many cities. Not everyone can be an expert car driver, majority of people are those who rely on inbuilt technology embedded inside the car. To provide the best solution for the people like Ravi, the most popular system used in cars is the parking assistance system.

Parking assistance system consists of ultrasonic sensors which are mounted on the rear and front bumpers. The purpose of these sensors is to echo out the high frequency acoustic sound wave for sensing the obstacle behind the car, thereby avoiding the collision of the car from the wall or any person or car behind the car. There are many commercially available parking assistance system, some have LCD display mounted inside the car for displaying the range of the obstacle behind the car.

What are ultrasounds?

The history and discovery of the ultrasound waves are connected to the navigation of bats in dark places. Study of the properties of this kind of sound waves, led to the development of many popular applications for the purpose of navigation and obstacle detection, exploring the depth of the oceans, detecting the foetus in the mother’s womb, analysing the flaws in the body of the solid material, cleaning and weapons. Ultrasonic sounds are high frequency sound waves, inaudible to human ears typically ranging above 20 KHz. Piezoelectric crystal inside the ultrasonic sensors vibrate at frequency of 40Khz, the vibrational waves echo out in the form of sonar waves. Many other types of ultrasonic sensors have electromagnetic device for the production of the ultrasound waves. 

How the sensor works?

image006-2.jpg

Ultrasound sensors consist of two units: Transmitting unit, Tx which works similar to a speaker and emits out sound wave of high frequency for few microseconds. On the other hand is Receiving unit, Rx which is activated after the TX sends out the sound wave, it’s working is similar to a microphone as it listens the echo of the sound after it bounces back from any obstacle. As and when the reflected sound wave is received by the receiver Rx, the control unit of the sensor records the overall time took by the sound wave in sending and returning to Rx of the sensor. Given the fact, the speed of the sound is 341 m/sec; it becomes easy to calculate the distance of the obstacle from the sensor. It is to be noted that more the time taken by the wave, greater is the distance between the sensor and obstacle and vice-versa.

Parallax Ping:

image008-3.jpg

This is 3 pin ultrasonic sensors, which can measure distance up to 2 cm to 3 meters. The single Bidirectional I/O pin makes it friendly with most controller boards available in market e.g. BS2, arduino. The 3 pins are: Vcc, Gnd, SIG (signal). The signal pin is the bi-directional pin configured as both trigger and echo.

HC-SR04: 

image010-4.jpg

This is the most popular ultrasonic sensor commonly used with arduino board. It has four pin configurations namely Trigger, Echo, Vcc, Gnd. The path time of the echo pulse starting from trigger to receiving of echo pulse is roughly 20ms. Therefore it is advisable to set the delay of more than 20ms for the echo pin to receive the echo pulse.

HC- SRF05:

image012-5.jpg

This is 5 pin ultrasonic sensor similar to the other ultrasonic sensors like HC-SR04; the only difference is the extra pin OUT, which switches the modes of the sensor between single pin operation and dual pin operation. In single pin mode, only one pin can be used as both Trigger/Echo. On the other hand in dual pin mode, the sensor is used like a 4 pin sensor HC-SR04.

US-100:

This type of ultrasonic sensor is different from the others discussed above; there are 5 pins on the sensor Vcc, GND1, GND2, Tx and Rx. This sensor outputs two types of signal, one is serial data output and other is pulse data output. The function of the extra pin is for the selection of the operating mode. The operating mode of the sensor is configured by using the jumper on the back of the module. When the jumper is present, the sensor outputs the distance as binary serial data, otherwise the sensor outputs a single pulse that has a width which represents the distance measured.

image014-6.jpg

Using the US-100 Distance Sensor in Serial Data Mode:

Place the shunt on the operating mode selection jumper to choose serial data mode. Attach the module to a serial port on your microcontroller. The Trig/TX pin connects to your microcontroller's TX serial transmits line. The Echo/RX pin connects to your microcontroller's RX serial receives line. Set the microcontroller's serial port to use 9600 baud at 8-N-1 (eight data bits, no parity, one stop bit).

To start measuring the distance, output a 0x55 over the serial port and read back the two byte distance in high byte, low byte format. The distance returned is measured in millimetres. Use the following formula to obtain the distance as millimetres:

Millimetres = FirstByteRead * 256 + SecondByteRead

This module can also output the temperature when using serial output mode. To read the temperature, output a 0x50 byte over the serial port and read back a single temperature byte. The actual temperature is obtained by using the following formula:

Celsius = Byte Read – 45

Using the US-100 Sensor in Pulse Width Mode:

Select the pulse mode by removing the shunt from the operating mode selection jumper. Connect the Trig/TX pin to a digital output on your microcontroller and the Echo/RX pin to a digital input.

To obtain a distance measurement, set the Trig/TX pin high for at least 50 microseconds then set it low to trigger the measurement. The module will output a high pulse on the Echo/RX line with a width that corresponds to the distance measured. Use your microcontroller to measure the pulse width using microseconds. Use the following formula to calculate the distance:

Millimetres = PulseWidth * 34 / 100 / 2.

Arduino with Ultrasonic Sensor:

image016-7.jpg

Arduino microcontroller board is the best way to understand the working of the ultrasonic sensor. The only requirement needed for the setup is the power source, breadboard, connecting wires and arduino IDE running on the computer/laptop.

Follow the instructions below for the connection of the board and the ultrasonic sensor:

  • Connect Vcc of the board to the sensor’s Vcc, which gives 5v output from arduino to sensor.
  • Similarly connect ground port of the arduino to gnd pin of sensor.
  • Select any two digital I/O pins from the connection of Tx and Rx of the sensor. In this case pin 9 and 10 is used.
  • Setup the arduino IDE and copy the code given below.

  • // defines pins numbers

    constinttrigPin = 9;

    constintechoPin = 10;

    // defines variables

    long duration;

    int distance;

    void setup() {

    pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output

    pinMode(echoPin, INPUT); // Sets the echoPin as an Input

    Serial.begin(9600); // Starts the serial communication

    }

    void loop() {

    // Clears the trigPin

    digitalWrite(trigPin, LOW);

    delayMicroseconds(2);

    // Sets the trigPin on HIGH state for 10 micro seconds

    digitalWrite(trigPin, HIGH);

    delayMicroseconds(10);

    digitalWrite(trigPin, LOW);

    // Reads the echoPin, returns the sound wave travel time in microseconds

    duration = pulseIn(echoPin, HIGH);

    // Calculating the distance

    distance= duration*0.034/2;

    // Prints the distance on the Serial Monitor

    Serial.print("Distance: ");

    Serial.println(distance);

    }


    Explanation of the code:

    The code first initializes the digital pin 9 and 10 for the Tx and Rx of the sensor.

    Trigger pin 9 is set low for 2ms, this resets the sensor.

    Now trigger pin 9 is set high for 10ms and then back to low.

    This short pulse of 10 ms allows the Tx of the sensor to echo out the ultrasonic burst in air.

    After this echo pin 10 is set high and pulseIn command record the time duration took by the sound wave in coming back to receiver end.

    This data is fed into the duration variable for the purpose of the calculation of the distance.

    This data of distance can be read in real time by the serial monitor in the end.

    image019-8.png