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 it takes for the echo to return. The HY-SRF05 is widely used in robotics, automation, and obstacle detection systems due to its accuracy, reliability, and ease of use.
The HY-SRF05 is designed to provide accurate distance measurements with minimal power consumption. Below are its key technical details:
Parameter | Value |
---|---|
Operating Voltage | 5V DC |
Operating Current | 15 mA |
Measuring Range | 2 cm to 400 cm |
Measuring Angle | 15° |
Frequency | 40 kHz |
Resolution | 0.3 cm |
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. Below is the pinout and description:
Pin | Name | Description |
---|---|---|
1 | VCC | Power supply pin (5V DC) |
2 | Trig | Trigger pin: Input 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 |
5 | OUT (NC) | Optional pin for mode selection (not commonly used; leave unconnected if unused) |
The HY-SRF05 is simple to use in a circuit. Follow the steps below to integrate it into your project:
VCC
pin to a 5V power source and the GND
pin to ground.Trig
pin to a digital output pin of your microcontroller (e.g., Arduino UNO).Echo
pin to a digital input pin of your microcontroller.OUT
pin unconnected unless you need to use it for specific configurations.Echo
pin.Below is an example Arduino sketch to measure distance using the HY-SRF05:
// 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() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Set pin modes
pinMode(trigPin, OUTPUT); // Set trigger pin as output
pinMode(echoPin, INPUT); // Set echo pin as input
}
void loop() {
// Send a 10 µs pulse to the trigger 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 centimeters
// Speed of sound = 343 m/s or 0.0343 cm/µs
// Distance = (duration / 2) * 0.0343
float distance = (duration / 2.0) * 0.0343;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Wait before the next measurement
delay(100);
}
pulseIn()
function measures the time (in microseconds) for which the Echo
pin remains HIGH.No Output or Incorrect Distance
Unstable or Fluctuating Readings
Distance Always Reads Maximum (400 cm)
Sensor Not Responding
Can the HY-SRF05 work with a 3.3V microcontroller?
Echo
pin to avoid damaging the microcontroller.What is the maximum range of the HY-SRF05?
Can the HY-SRF05 detect transparent objects?
How accurate is the HY-SRF05?
By following this documentation, you can effectively integrate the HY-SRF05 ultrasonic distance sensor into your projects and troubleshoot common issues.