How To Measure Distance Using Ultrasonic Distance Meter
Ultrasonic distance meter
An ultrasonic distance meter an Arduino meter which measure a short duration distance and show distance on the serial monitor.
An ultrasonic sensor is a device that can measure the distance to An object by using sound waves. It measures distance by sending out a sound wave at a specific frequency and snooping for that sound wave to bounce back. By recording the passed time between the sound wave being produced and the sound wave bouncing back, it is possible to calculate the distance between the sonar sensor & the object Distance = Time x speed of Sound divided by 2.
In sea ships similarly used these type of Sonars used for determining the depth of the ocean.
Arduino UNO At Mega 328
An Arduino main programmable controlling circuit which controls the outputs and inputs according to user desired technics
This circuit has reduced a large other many circuit connection replace by user programming codes to upload Or simply said that “All in one” circuit.
Following is an Arduino board showing its different parts with its names.
An ultrasonic sensor commonly 4 pins used but some sensors have 5th pin also which used for LCD display showing result having the name “OUT”.
Task: Measuring a distance using the HC-SR04 ultrasonic sensor and display the result on the serial monitor. Required equipment: Microcontroller board/cables/ Breadboard / HC-SR04 ultrasonic sensor how does the ultrasonic sensor work?
The sensor has four pins.
- 5V (+) b) GND (-) c) Echo d) Trigger
The contacts 5V and GND are meant for the power supply. Using the “trigger” pin the sensor receives a short signal (5V) from the microcontroller board to create a sound wave. As soon as the sound wave hits a wall or other objects, it will be reflected and comes back to the ultrasonic sensor.
When the sensor detects this returned sound wave, the sensor will send a signal to the Arduino microcontroller through the “echo” pin. The Arduino-board is used here to quantify and measures the time between the transmission and the return of the sound wave and converts this time into a distance.
Jumper wires & Brad Board
Jumper wires are used for connection pathway signals and current carrying (materials) lines.
A small brad board use for connecting board without soldering plug in and plug out make easier by its one-sided holes. The Row-wise holes are commonly used for power supply VCC+ and GND. The center narrow hollow path is used for IC installation.
- Install the ultra-sonic sensor in brad board tightly
- The take a wire from “Vcc” to Arduino UNO to +5VPin.
- Take the 2nd wire from “Trig” to Arduino any digital pin.
- “Echo” pin must connect to any “PWM” pin of UNO.
- Provide “GND” ground connection from any pin of UNO have GND naming.
- The power supply ( +Ive & GND ) to UNO through its USB cable from laptop or PC and the UNO provide supply to the ultrasonic sensor.
We want to measure the distance to check between 0 and 200 cm. for this purpose we make a code to explain it.
- 1st of all we de define trig pin to pin 11 and echo pin to 12
- For output limitation blinking we add a LED connected to pin 13 and second to 10.
Setup of Inputs & Outputs:-
- Trigger pin must have for output to Arduino
- Echo pin must generate echo inputs to rappel any object.
- Both leads we want to output show blink on a specific distance.
Looping of Commands;-
- Insert the long duration and distance library
- Stop the trig pin for 2u seconds
- Make a high trigger pin for 10u seconds.
- While low the trig pin oppositely echo pin high 10us & measure the time (duration ) in both travels
- We know that Distance=time/velocity But here by rippling the time is duel elapsed that’s why dived Total time by 2.
- Here is the constant velocity of ultrasound waves in small sensors are 29.1m/s.
- We use “if ” condition for more than one possibilities
- If the distance is less than 4cm then make led ON and led2 must be OFF.
- Else if the condition is opposite mean distance larger than 4cm then led make OFF and led2 make high.
- If the distance is less or equal to 0cm and greater or equal to 200cm then aware me that “Out of range “
- I want distance numerical value showing by serial monitor
- And print length in “cm”
- After every half of the second show me result on the serial monitor
- Remember that (1second=1000u seconds).