

The HY-SRF05 is an ultrasonic distance sensor manufactured by Raspberry Pi 4, with the part ID "Ultrasonic distance sensor." This sensor uses sonar technology to measure the distance to an object by emitting ultrasonic waves and calculating the time taken for the echo to return. It is widely used in robotics, automation, and obstacle detection systems due to its accuracy and ease of use.








The HY-SRF05 is designed to provide reliable and accurate distance measurements. Below are its key technical details:
| Parameter | Value |
|---|---|
| Operating Voltage | 5V DC |
| Operating Current | 15 mA (typical) |
| Measuring Range | 2 cm to 4 m |
| Accuracy | ±3 mm |
| Operating Frequency | 40 kHz |
| Trigger Input Signal | 10 µs TTL pulse |
| Echo Output Signal | Pulse width proportional to distance |
| Dimensions | 45 mm x 20 mm x 15 mm |
The HY-SRF05 has a 5-pin interface for easy integration into circuits. Below is the pinout:
| Pin | Name | Description |
|---|---|---|
| 1 | VCC | Power supply pin. Connect to 5V DC. |
| 2 | Trig | Trigger pin. Send a 10 µs TTL pulse to initiate distance measurement. |
| 3 | Echo | Echo pin. Outputs a pulse width proportional to the measured distance. |
| 4 | GND | Ground pin. Connect to the ground of the power supply. |
| 5 | OUT (optional) | Optional output pin for additional functionality in some configurations. |
The HY-SRF05 is simple to use and can be integrated into a variety of circuits. Below are the steps to use the sensor:
Below is an example code to use the HY-SRF05 with an Arduino UNO:
// Define pins for the HY-SRF05 sensor
const int trigPin = 9; // Trigger pin connected to digital pin 9
const int echoPin = 10; // Echo pin connected to digital pin 10
void setup() {
pinMode(trigPin, OUTPUT); // Set the trigger pin as an output
pinMode(echoPin, INPUT); // Set the echo pin as an input
Serial.begin(9600); // Initialize serial communication at 9600 baud
}
void loop() {
// Send a 10 µs pulse to the Trig pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the duration of the echo pulse
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance in cm
float distance = duration / 58.0;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500); // Wait for 500 ms before the next measurement
}
No Output from the Sensor
Inaccurate Distance Measurements
Echo Pin Always HIGH or LOW
Q: Can the HY-SRF05 measure distances below 2 cm?
A: No, the minimum measurable distance is 2 cm. Objects closer than this may not be detected accurately.
Q: Can I use the HY-SRF05 with a 3.3V microcontroller?
A: The HY-SRF05 requires a 5V power supply. However, you can use a voltage divider or level shifter to safely interface the Echo pin with a 3.3V microcontroller.
Q: What is the maximum angle of detection for the HY-SRF05?
A: The sensor has a detection angle of approximately 15 degrees. Ensure objects are within this cone for accurate measurements.