top of page

Tutorial-3 Ultrasonic Sensor Interfacing with Arduino In Advance Level

Updated: Sep 4, 2019


Introduction :

     SONAR basically stands for Sound Navigation and Ranging. Ultrasonic is mostly used for the distance measurement prototype applications. It can also be used for measuring the depth of the sea. Ultrasonic/SONAR sensor is an electronic device used to estimate the distance of an object by continuously transmitting sound waves at a particular frequency and listens to that transmitted sound wave to bounce back. It measures the time between the transmission and receiving of that sound wave, which is actually equal to the distance of an object from the SONAR. An optical sensor has both a transmitter to transmit and a receiver to receive the waves. But in comparison to that optical sensor ultrasonic sensor has only a single element for both transmitting and receiving ultrasonic/sound waves. Here i share ultrasonic sensor interfacing and its advance level applications designing like street light controller, vehicle parking systems.



Table of Content:

 1. List of Inventories

    1.1 Hardware Requirements

    1.2 Software Requirements

    1.3 Brief Introduction of component and calculate resistance 2. System Modelling

    2.1 Circuit Diagram

     2.2 Source Code Programming

           2.2.1 Ultrasonic Sensor Interfacing with Arduino

           2.2.2 Ultrasonic Sensor and LCD interfacing with Arduino

          2.2.3 Street light Intensity Controller

           2.2.4 Autonomous Liquid level Controller            2.2.5 Vehicle Parking Sensors

     2.3 How to get .hex file

     2.4 Detail explanation of code


1. List of Inventories:

    1.1 Hardware:

        1. Liquid Crystal Display (16x 2 )         2. Ultrasonic Sensor (HCSR-04)

        3. Jumper wires - 15

        4. Resistor: 65 ohm

        5. Potentiometer: 1k ohm

        6. Power Supply: 1) 9 to 12 Vdc & <= 1A (For Arduino)

                                      2) 5 to 9 Vdc (For LCD)

           Development Board: Arduino or Genuino UNO

1.2 Software and Library:

       1. Arduino Software

1.2 Arduino for Linux OS

                 1.2.1 For LINUX ARM                  1.2.2 For LINUX ARM64                  1.2.3 For LINUX 32-bit                 1.2.4 For LINUX 64-bit

        3. Library

3.2 Genuino Library for Proteus             3.3 LCD Library for Proteus             3.4 Ultrasonic Sensor Library for Proteus


       1.3 Brief introduction of the components:             1) Arduino UNO             2) LED             3) LCD             4) Ultrasonic Sensor :


HCSR-04 Ultrasonic Sensor

Ultrasonic sensor is also known as SONAR. It is used for measuring the distance between the object and the sensor itself. It transmits ultrasonic waves and receives it back after reflecting from the surface of an object. Then its measures the time during entire process which is equal to the distance between object and the sensor itself. It has four pins and is very easy to use. It is easily available in the market and is available at very low cost. It has a wide range of applications e.g. estimating the sea’s depth and many more. SONAR/ultrasonic sensor along with proper labeling is given in the figure shown below. 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. How Ultrasonic Sensor work : 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. 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 traveled. For example, if the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward.  So in order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2. Example :

  • V (Speed of Sund) =  340m/s  = 0.03 cm/4us

  • D (Distance) = 10 cm

  • T (Time = Distance (D) / Time) = 10/0.034 = 294 us

  • Distance = T X 0.034 / 2 


Pin configuration of Ultrasonic Sensor :

Pin Number : 1 | Pin Name : Vcc |

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


Pin Number : 2 | Pin Name : Trigger |

Description : Trigger pin is an Input pin.


Pin Number : 3 | Pin Name : Echo |

Description : 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 US wave to return back to the sensor.


Pin Number : 4 | Pin Name : GND |

Description : This pin is connected to the Ground of the system.


Features :

  • Operating voltage : +5V

  • Theoretical  Measuring Distance : 2cm to 450cm

  • Practical Measuring Distance : 2cm to 80cm

  • Accuracy : 3mm

  • Measuring angle covered : <15°

  • Operating Current : <15mA

  • Operating Frequency : 40Hz

 2. System modelling:

      2.1 Circuit Diagram




2.2 Source Code programming:       2.1.1 Ultrasonic Sensor Interfacing with Arduino       Click Here to download the code -1  

  Click Here to download the code -2 

             



Result: 

Click here to simulate this project


2.1.2 Ultrasonic Sensor and LCD  Interfacing with Arduino Now we are going to interface ultrasonic distance sensor HC-SR04 (proximity sensor) with Arduino and LCD. Ultrasonic sensor is used to measure the distance. It is also known as the proximity sensor or the sonar sensor. It sends an ultrasonic wave (sound wave) which comes back after hitting the object and tells us the time traveled by it. By using this time we calculate the distance traveled. The working of distance sensor is explained briefly in this tutorial. For displaying the data on the LCD. We will connect a 16X2 LCD with the Arduino. Connect the wires as shown in the diagram. 

Result: 

Download the code from here


2.1.3 Street Light Intensity Controller Now we are going to interface ultrasonic  with Arduino and LED.  Ultrasonic sensor is used to check the availability of vehicle. sends an ultrasonic wave (sound wave) which comes back after hitting the object and tells us the vehicle status By using this time we calculate the distance traveled. If vehicle is near the street light then light starts glowing with low intensity and increase further by moving vehicle 

Result: 

Download the code from here



2.1.4 Autonomous Liquid level controller Now we are going to interface ultrasonic sensor only with Arduino .Ultrasonic sensor is used to check the  availability of liquid present in the tank. sends an ultrasonic wave (sound wave) which comes back after hitting the level and tells us the liquid level status By using this time we calculate the distance traveled. If  liquid in tank is filled then motor will turn OFF and Turn ON when tank is empty.

Result:  Published by, Electronics with shreyash

Download the code from here



2.1.5 Vehicle Parking System Now we are going to interface two ultrasonic sensor with Arduino .  Ultrasonic sensor is used to check  the  availability of Parking Area then sends an ultrasonic wave (sound wave) which comes back  after hitting the obstacle and tells us the parking  status By using this time we calculate the distance traveled. If  distance is minimum on vehicle dashboard LED starts glowing is either if distance is minimum  is left side or if right side distance is minimum the LED will glow accordingly.


Result: 

Download the code from here



See also

Join our Community :



Comments


Post: Blog2_Post
bottom of page