Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use HY-SRF05: Examples, Pinouts, and Specs

Image of HY-SRF05Design with HY-SRF05 in Cirkit Designer

Introduction

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.

Explore Projects Built with HY-SRF05

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Arduino Mega 2560 Bluetooth-Controlled Ultrasonic Distance Measurement: A project utilizing HY-SRF05 in a practical application
Arduino Mega 2560 Bluetooth-Controlled Ultrasonic Distance Measurement

This circuit features an Arduino Mega 2560 microcontroller interfaced with an HC-05 Bluetooth Module and an HC-SR04 Ultrasonic Sensor. The HC-05 is powered by the Arduino's VIN pin and is grounded to the Arduino's GND, enabling wireless communication capabilities. The HC-SR04 is powered by the Arduino's 5V output and uses two digital PWM pins (D7 for TRIG and D6 for ECHO) to measure distances via ultrasonic waves.

Open Project in Cirkit Designer

Common Applications

Technical Specifications

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

Pin Configuration

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)

Usage Instructions

The HY-SRF05 is simple to use in a circuit. Follow the steps below to integrate it into your project:

Connecting the HY-SRF05

  1. Power the Sensor: Connect the VCC pin to a 5V power source and the GND pin to ground.
  2. Trigger Signal: Connect the Trig pin to a digital output pin of your microcontroller (e.g., Arduino UNO).
  3. Echo Signal: Connect the Echo pin to a digital input pin of your microcontroller.
  4. Optional Pin: Leave the OUT pin unconnected unless you need to use it for specific configurations.

Important Considerations

Example Code for Arduino UNO

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);
}

Notes on the Code

Troubleshooting and FAQs

Common Issues

  1. No Output or Incorrect Distance

    • Cause: Improper wiring or loose connections.
    • Solution: Double-check all connections and ensure the sensor is powered correctly.
  2. Unstable or Fluctuating Readings

    • Cause: Electrical noise or interference.
    • Solution: Use decoupling capacitors near the power pins and ensure the sensor is not near ultrasonic noise sources.
  3. Distance Always Reads Maximum (400 cm)

    • Cause: No object within range or incorrect trigger signal.
    • Solution: Ensure an object is within the sensor's range and verify the trigger signal timing.
  4. Sensor Not Responding

    • Cause: Faulty sensor or incorrect pin configuration.
    • Solution: Test the sensor with a different microcontroller and verify the pin connections.

FAQs

  1. Can the HY-SRF05 work with a 3.3V microcontroller?

    • Yes, but you need a level shifter or resistor divider for the Echo pin to avoid damaging the microcontroller.
  2. What is the maximum range of the HY-SRF05?

    • The sensor can measure distances up to 400 cm (4 meters).
  3. Can the HY-SRF05 detect transparent objects?

    • No, the sensor may struggle to detect transparent or very small objects due to poor ultrasonic wave reflection.
  4. How accurate is the HY-SRF05?

    • The sensor has a resolution of 0.3 cm, but environmental factors may slightly affect accuracy.

By following this documentation, you can effectively integrate the HY-SRF05 ultrasonic distance sensor into your projects and troubleshoot common issues.