The ultrasonic sensor measures the distance of the nearest object, sending the result to the serial port. It can work from 2 cm to 3 m. It measures the time spent by the signal to reach the object and return to the sensor.
Connections:
- Vcc -> 5 V
- Trig -> pin 13 (digital pin)
- Echo -> pin 12 (digital pin)
- Out ->
- GND -> GND
Sonar Technology Overview
The HY-SRF05 Ultrasonic Ranging Project is a fundamental lesson in "Non-Contact Measurement." While simple to wire, it introduces builders to the physics of acoustics and the mathematics of speed, time, and distance. The HY-SRF05 is an evolved version of the classic HC-SR04, offering higher precision and the ability to operate in many different wiring modes. This project is the first step toward building autonomous robots that can "see" obstacles.
Hardware Core & Detection Tier
- Arduino UNO: Functions as the master timekeeper. It generates the precise 10-microsecond trigger pulse and measures the return echo with microsecond granularity.
- HY-SRF04/05 Ultrasonic Sensor: The system's "Acoustic Transceiver."
- Transmitter (T): Emits a 40kHz ultrasonic burst (invisible and inaudible).
- Receiver (R): Listens for the "echo" bouncing back from a solid surface.
- Pins and Mode:
- Trig (Pin 13): Input pin used to start the measurement.
- Echo (Pin 12): Output pin that goes HIGH for a duration equal to the flight time of the sound.
- Out (MODE Pin): On the SRF05, this pin can be used to set 1-pin or 2-pin operation.
Dimensional Logic and Math
The distance calculation is based on the universal Speed of Sound (approx. 343 m/s at room temperature):
- The Pulse Cycle: The Arduino sends a 10us HIGH pulse to the
Trigpin. The sensor responds by shooting out 8 cycles of ultrasonic sound. - Timing the Flight: The
Echopin turns HIGH. The Arduino uses thepulseIn()function to wait until the pin turns LOW, giving the total "Time of Flight" in microseconds. - Calculating Centimeters:
- Since the sound traveled to the object and back, we divide the time by 2.
- Using the constant
0.0343(cm per microsecond), the distance is:Distance = (Time / 2) * 0.0343.
- Data Reporting: The final value is printed to the Serial Monitor in a human-readable format (e.g., "15.4 cm").
Why This Project is Important
This build teaches the fundamentals of Pulse-Width Timing and Acoustic Physics. It demonstrates how to translate an invisible environmental phenomenon into a tangible digital variable. Once mastered, you can use this distance data to trigger alarms (Parking Sensors), drive motors (Obstacle Avoiding Robots), or even measure liquid levels in a water tank (IoT Tank Monitor).