GLOBAL ACADEMY OF TECHNOLOGY
Approved by AICTE, New Delhi, Recognized by the Govt. of Karnataka
Autonomous Institute affiliated to VTU, Belagavi,
NAAC Accredited with ‘A’ Grade
Ideal Homes Township, RajaRajeshwari Nagar, Bengaluru-98
SMART IOT MINIPROJECT
PROJECT REPORT
Title: Ultrasonic Distance Measurement System
Submitted by: Arun Balajee A P
USN: 1GA21CS030
1. Introduction
Distance measurement is a crucial aspect of various applications, including
robotics, automation, and security systems. The ultrasonic sensor is a
reliable and cost-effective solution for measuring distances with high
accuracy. This project implements an ultrasonic distance measurement
system using an Arduino (or ESP32) microcontroller and an HC-SR04
ultrasonic sensor. The system calculates and displays the distance of an
object from the sensor in real-time.
2. Objectives
• To develop an ultrasonic distance measurement system using an
Arduino/ESP32.
• To integrate an ultrasonic sensor for real-time distance measurement.
• To display the measured distance on a serial monitor.
• To ensure efficient and accurate readings for various applications.
3. Components Used
1. Microcontroller - Arduino/ESP32
2. Ultrasonic Sensor - HC-SR04
3. Resistors and Wires - For circuit connections
4. Power Supply - 5V DC
5. Software - Arduino IDE
4. Circuit Diagram
The circuit consists of an HC-SR04 ultrasonic sensor connected to the
microcontroller. The Trigger (TRIG) Pin is connected to GPIO 5, and the Echo
(ECHO) Pin is connected to GPIO 18. The sensor emits ultrasonic waves,
which are reflected by an obstacle and received back by the sensor, allowing
the system to calculate the distance.
5. Working Principle
The system operates using the time-of-flight principle, where the sensor
sends out an ultrasonic pulse, which bounces off an object and returns to
the sensor.
Distance=Time×0.0342\text{Distance} = \frac{\text{Time} \times 0.034}{2}
where 0.034 is the speed of sound in cm/µs, and the division by 2 accounts
for the round-trip time.
6. Code Implementation
// Pin definitions
#define TRIG_PIN 5 // Define the GPIO pin for the trigger
#define ECHO_PIN 18 // Define the GPIO pin for the echo
long duration; int
distance;
void setup() {
Serial.begin(115200);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
Serial.println("Ultrasonic Sensor Initialized.");
void loop() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm"); delay(1000);
7. Results and Observations
• The system successfully measures distances accurately in real-time.
• The serial monitor displays the measured distance in centimeters.
• The response time of the sensor is quick, ensuring efficient readings.
• The system performs well in indoor environments but may require
calibration in outdoor conditions.
8. Applications
• Robotics: Autonomous obstacle detection and navigation.
• Security Systems: Intruder detection in restricted areas.
• Smart Vehicles: Parking assistance and collision detection.
• Industrial Automation: Object distance measurement in
manufacturing units.
•
9. Conclusion
This project successfully demonstrates a real-time ultrasonic distance
measurement system using an HC-SR04 sensor and a microcontroller. The
system is reliable, efficient, and has various practical applications in
automation, robotics, and security. Future enhancements may include
integrating an LCD display, wireless data transmission, or multiple sensors
for enhanced accuracy.
10. References
• Datasheet of HC-SR04 Ultrasonic Sensor
• Arduino Documentation
• Online tutorials on ultrasonic distance measurement
Submitted by:
Arun Balajee A P
USN: 1GA21CS030