Anda di halaman 1dari 6

16/12/2018 Distance Measurement using Arduino Ultrasonic Sensor: Code & Circuit Diagram

Patient Reported Outcomes


Child Health Questionnaire
Child Health Questionnaire Measures 14 Unique Physical and Psychosocial Concepts

healthactchq.com OPEN

ARDUINO (HTTPS://CIRCUITDIGEST.COM/ARDUINO-PROJECTS)

Arduino & Ultrasonic Sensor Based Distance Measurement


(/microcontroller-projects/arduino-ultrasonic-sensor-based-distance-
measurement)
By (page_author.html)Saddam (/users/saddam)  Jun 27, 2015 47

This website uses cookies to improve user experience. By using the website you are giving your
consent to set cookies. For more information, read our cookie policy (https://circuitdigest.com/cookie- OK, I Understand 
policy) and privacy policy (http://circuitdigest.com/privacy-policy).

https://circuitdigest.com/microcontroller-projects/arduino-ultrasonic-sensor-based-distance-measurement 1/22
16/12/2018 Distance Measurement using Arduino Ultrasonic Sensor: Code & Circuit Diagram

Distance Measurement using Arduino & Ultrasonic Sensor

Ultrasonic sensors are great tools  to measure distance without actual contact and used at several places like  water level measurement, distance
measurement etc. This is an e cient way  to measure small distances precisely. In this project we have used an  Ultrasonic Sensor  to determine the
distance of an obstacle from the sensor. Basic principal of ultrasonic distance measurement is based on ECHO. When sound waves are transmitted in
environment then waves are return back to origin as ECHO after striking on the obstacle. So we only need to calculate the travelling time of both sounds
means outgoing time and returning time to origin after striking on the obstacle. As speed of the sound is known to us, after  some calculation we can
calculate the distance.   
SPONSORED SEARCHES

Schematic Diagram

Water Level Sensor

Components Used
1. Arduino Uno or Pro Mini
2. Ultrasonic sensor Module
3. 16x2 LCD
4. Scale
5. Bread board
6. 9 volt battery
7. Connecting wires

Ultrasonic Sensor Module


Ultrasonic sensor HC-SR04 is used here to measure distance in range of 2cm-400cm with accuracy of 3mm. The sensor module consists of ultrasonic
This website
transmitter, receiver and theuses cookies
control to improve
circuit. user principle of
The working experience.ultrasonic
By using the website
sensor is asyou are giving your
follows:
consent to set cookies. For more information, read our cookie policy (https://circuitdigest.com/cookie- OK, I Understand 
1. Highpolicy)
level signal is sentpolicy
and privacy for 10us using Trigger.
(http://circuitdigest.com/privacy-policy).

https://circuitdigest.com/microcontroller-projects/arduino-ultrasonic-sensor-based-distance-measurement 2/22
16/12/2018 Distance Measurement using Arduino Ultrasonic Sensor: Code & Circuit Diagram

2. The module sends eight 40 KHz signals automatically, and then detects whether pulse is received or not.
3. If the signal is received, then it is through high level. The time of high duration is the time gap between sending and receiving the signal.

Distance= (Time x Speed of Sound in Air (340 m/s))/2

Timing Diagram

The module works on the natural phenomenon of ECHO of sound. A pulse is sent for about 10us to trigger the module. After which the module
automatically sends 8 cycles of 40 KHz ultrasound signal and checks its echo. The signal after striking with an obstacle returns back and is captured by
the receiver. Thus the distance of the obstacle from the sensor is simply calculated by the formula given as

            Distance= (time x speed)/2.

Here we have divided the product of speed and time by 2 because the time is the total time it took to reach the obstacle and return back. Thus the time to
reach obstacle is just half the total time taken.

Raspberry Pi DIY
Hydroponics
pH, DO, EC, ORP, ow, level
Components for building your own
Raspberry Pi based hydroponics controller

whiteboxes.ch OPEN

Circuit Diagram and Explanation

This website uses cookies to improve user experience. By using the website you are giving your
consent to set cookies. For more information, read our cookie policy (https://circuitdigest.com/cookie- OK, I Understand 
policy) and privacy policy (http://circuitdigest.com/privacy-policy).

https://circuitdigest.com/microcontroller-projects/arduino-ultrasonic-sensor-based-distance-measurement 3/22
16/12/2018 Distance Measurement using Arduino Ultrasonic Sensor: Code & Circuit Diagram

SPONSORED SEARCHES

Temperature Sensor

Schematic Diagram
(/fullimage?

i=circuitdiagram_mic/Arduino-Distance-measurement-using-ultrasonic-Sensor-circuit.png)

Raspberry Pi DIY Hydroponics - pH, DO, EC, ORP, ow,


OPEN
level
Components for building your own Raspberry Pi based hydroponics controller whiteboxes.ch

The circuit diagram for arduino and ultrasonic sensor is shown above to measure the distance. In circuit connections Ultrasonic sensor module’s “trigger”
and “echo” pins are directly connected to pin 18(A4) and 19(A5) of arduino. A 16x2 LCD is connected with arduino in 4-bit mode. Control pin RS, RW and En
are directly connected to arduino pin 2, GND and 3. And data pin D4-D7 is connected to 4, 5, 6 and 7 of arduino.

First of all we need to trigger the ultrasonic sensor module to transmit signal by using arduino and then wait for receive ECHO. Arduino reads the time
between triggering and Received ECHO. We know that speed of sound is around 340m/s. so we can calculate distance by using given formula:

Distance= (travel time/2) * speed of sound

Where speed of sound around 340m per second.

A 16x2 LCD is used for displaying distance.

Find more about the working of distance measurement project in this tutorial: Distance measurement using ultrasonic sensor
(http://circuitdigest.com/microcontroller-projects/distance-measurement-using-hc-sr04-avr).

Distance Measurement using Arduino &


Ultrasonic Sensor
Arduino Nano can also be used with Ultrasonic Sensor

This website uses cookies to improve user experience. By using the website you are giving your
Arduino Ultrasonic Code
consent to set cookies. forinformation,
For more Distance readMeasurement
our cookie policy (https://circuitdigest.com/cookie- OK, I Understand 
policy) and privacy policy (http://circuitdigest.com/privacy-policy).

https://circuitdigest.com/microcontroller-projects/arduino-ultrasonic-sensor-based-distance-measurement 4/22
16/12/2018 Distance Measurement using Arduino Ultrasonic Sensor: Code & Circuit Diagram

In code we read time by using pulseIn(pin). And then perform calculations and displayed result on 16x2 LCD by using appropriate functions.

Code
#include <LiquidCrystal.h>

 
#de ne trigger 18

#de ne echo 19

LiquidCrystal lcd(2,3,4,5,6,7);

oat time=0,distance=0;

 
void setup()

 lcd.begin(16,2);

 pinMode(trigger,OUTPUT);

 pinMode(echo,INPUT);

 lcd.print(" Ultra sonic");

 lcd.setCursor(0,1);
 lcd.print("Distance Meter");

 delay(2000);

 lcd.clear();

 lcd.print(" Circuit Digest");

 delay(2000);

}
 

void loop()

 lcd.clear();

 digitalWrite(trigger,LOW);

 delayMicroseconds(2);

 digitalWrite(trigger,HIGH);
 delayMicroseconds(10);

 digitalWrite(trigger,LOW);

 delayMicroseconds(2);

 time=pulseIn(echo,HIGH);

 distance=time*340/20000;

 lcd.clear();

 lcd.print("Distance:");
 lcd.print(distance);

 lcd.print("cm");
This website uses cookies to improve user experience. By using the website you are giving your
 lcd.setCursor(0,1);
consent to set cookies. For more information, read our cookie policy (https://circuitdigest.com/cookie-
 lcd.print("Distance:");
OK, I Understand 
policy) and privacy policy (http://circuitdigest.com/privacy-policy).

https://circuitdigest.com/microcontroller-projects/arduino-ultrasonic-sensor-based-distance-measurement 5/22
16/12/2018 Distance Measurement using Arduino Ultrasonic Sensor: Code & Circuit Diagram

 lcd.print(distance/100);
 lcd.print("m");

 delay(1000);

Video

Distance Measurement using Ultrasonic Sensor and Arduino

TAGS ARDUINO (/TAGS/ARDUINO) ULTRASONIC SENSOR (/TAGS/ULTRASONIC-SENSOR) HC SR04 (/TAGS/HC-SR04)

EMBEDDED (/TAGS/EMBEDDED)

JLCPCB Prototype: Only $2 for 10 pcs PCBs, 48 Hours Quick Turn (https://jlcpcb.com/)
JLCPCB, with 300,000+ Customers Worldwide, 8,000+ PCB Orders Per Day. (https://jlcpcb.com)

Quote and Order boards in minutes on https://jlcpcb.com/quote (https://jlcpcb.com/quote)

Raspberry Pi DIY Arduino based AC Dimmer Arduino How To Measure


Hydroponics - pH, DO, Automatic Water Raspberry - 110V/220V Distance Between
EC, ORP, flow, level Level Indicator and... Programmable Dimmer Two Ultrasonic...
Ad whiteboxes.ch circuitdigest.com Ad electronicnuts.com circuitdigest.com

Density Meter Arduino Based Floor Arduino Radar Mobile Phone


Cleaning Robot using System using Controlled Robot Car
Ultrasonic Sensor Processing Android... using G-Sensor and...

Ad Muser Apac Sdn. Bhd. circuitdigest.com circuitdigest.com circuitdigest.com

This website uses cookies to improve user experience. By using the website you are giving your
Get Our Weekly Newsletter!
consent to set cookies. For more information, read our cookie policy (https://circuitdigest.com/cookie- OK, I Understand 
policy) and privacy policy (http://circuitdigest.com/privacy-policy).
Subscribe below to receive most popular news, articles and DIY projects from Circuit Digest
https://circuitdigest.com/microcontroller-projects/arduino-ultrasonic-sensor-based-distance-measurement 6/22