Blog
5 Pin HY-SRF05 Ultrasonic Module
Are you still troubled by the distance detection in your project? The 5-pin ultrasonic module HY-SRF05 might be the “treasure sensor” you’ve been looking for! It is widely applicable to various intelligent hardware projects such as robot obstacle avoidance, automatic door control, and intelligent parking systems. Check out this detailed HY-SRF05 tutorial to master ultrasonic ranging – the HY SRF05 manual makes it a breeze for beginners!
If you are a beginner in electronic construction, or are looking for a cost-effective and highly reliable distance detection sensor, the HY-SRF05 price is unbeatable for its accuracy, and the HY SRF05 manual covers everything from wiring to code examples!
What is HY-SRF05 Ultrasonic Module?
The HY-SRF05 is a distance measurement module based on the ultrasonic principle. It emits 40kHz ultrasonic waves and receives the echoes to calculate the distance from the obstacle. It has 5 pins (VCC, Trig, Echo, OUT, GND), supports multiple triggering methods, and can be controlled by a microcontroller or used independently, which is very flexible!
Its working voltage is 5V, the measurement range is usually between 2cm and 450cm, and the accuracy can reach up to 3mm. It is very suitable for scenarios such as robot obstacle avoidance, smart home sensing, and automatic parking systems. What’s great is that it has strong anti-interference ability, is not sensitive to environmental factors such as light, color, and smoke, and has good stability.
Working Principle
· HY SRF05 Schematic Diagram
Using the microcontroller programming to generate a 40kHz square wave, which is then amplified by the transmission drive circuit, causing the transmitting end of the ultrasonic sensor to oscillate and emit ultrasonic waves. The ultrasonic waves are reflected back by the target object (obstacle) and received by the receiving end of the sensor. They are then amplified and shaped by the receiving circuit. When the reflected wave of the ultrasonic wave is received, the output end of the receiving circuit generates a transition. Through timer counting, the time difference can be calculated, and the corresponding distance can be determined.
- Use the IO port Trig to trigger distance measurement, providing a high-level signal for at least 10us.
- The module automatically sends eight 40kHz square waves and automatically detects whether there is a signal return.
- If a signal return is detected, a high level signal is output through the IO port Echo, and the duration of the high level is the time from the emission to the return of the ultrasonic wave.
Test distance = (High-level time × Sound speed (340m/s)) / 2
- Sequence chart
The sequence diagram shows that you only need to provide a pulse trigger signal of more than 10us. The module will internally generate eight 40KHz cycles and detect the echo. Once an echo signal is detected, an echo signal will be output. The pulse width of the echo signal is proportional to the measured distance. From the time interval between sending the signal and receiving the echo signal, the distance can be calculated.
- It is recommended that the measurement period be more than 60ms to prevent the influence of the transmitted signal on the echo signal.
HY-SRF05 Feature
- The HY-SRF05 ultrasonic distance measurement module offers non-contact distance sensing capabilities ranging from 2cm to 450cm.
- The measurement accuracy can reach up to 3mm.
- The module consists of an ultrasonic transmitter, receiver, and control circuit.
HY-SRF05 Pin Functions
· HY SRF05 Pin Diagram
VCC | 5V power supply (Power terminal) |
GND | Ground wire (Common ground) |
Trig | Trigger control, signal input. By inputting a trigger signal through this pin, a 10us high-level trigger module is activated. The module automatically sends eights 40KHz square waves for one distance measurement. |
Echo | Signal output, echo signal reception. This pin can output a high level after receiving the echo signal. The duration of the high level is the time it takes for the ultrasonic wave to travel from the emission point to the return point. |
OUT | Switching output, which can be used as an alarm module. It is a module status port. By judging the high or low level of OUT, it can determine whether the module is powered on. It is basically not used. |
HY SRF05 Specifications
Parameter | Value |
Working Voltage | DC 5V |
Operating Current | 15mA |
Working Frequency | 40Hz |
The Farthest Shooting Range | 4.5m |
The Most Recent Range | 2cm |
Measuring Angle | 15° |
Measurement Accuracy | ±2mm |
Input Trigger Signal | A 10us TTL pulse |
Output Echo Signal | Output TTL level signal, proportional to the range |
Specification and Dimension | 45mm * 21mm * 16mm |
HY SRF05 VS HC SR04
Module | HY-SRF05 | HC-SR04 |
Measuring Range | 2cm – 450cm (better long-range) | 2cm – 400cm (slightly shorter) |
Noise Resistance | Better (auto-calibration) | Standard (may need manual tuning) |
Idle Current | <2mA (lower standby power) | about 2-4mA (varies by module) |
Price | Slightly higher | Cheaper |
HY SRF05 Arduino
HY SRF05 Pinout
VCC ——> 5V Trig ——> D9
GND ——> GND Echo ——> D10
HY SRF05 Wiring Diagram
· Simulated Wiring Diagram
· Physical Wiring Diagram
HY SRF05 Arduino Code
#include
#include
#include
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int trigPin = 9;
const int echoPin = 10;
const float soundSpeed = 0.034; // cm/µs
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
while(1);
}
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Distance Meter");
display.display();
delay(500);
}
void loop() {
// Send pulse
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure echo
long duration = pulseIn(echoPin, HIGH, 30000);
float distance = duration * soundSpeed / 2;
// Serial output (distance only)
if(distance > 0 && distance <= 400) {
Serial.println(distance, 1); // 1 decimal place
} else {
Serial.println("no"); // Error code
}
// OLED display
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.println("Distance:");
display.setTextSize(2);
display.setCursor(0,20);
if(duration == 0) {
display.println("No echo");
}
else if(distance > 400) {
display.println("Over range");
}
else if(distance <= 0) {
display.println("Invalid");
}
else {
display.print(distance, 1);
display.println(" cm");
}
display.display();
delay(200);
}
Effect Demonstration
Application Note
- This module should not be connected with power. If you want to connect it with power, please first connect the GND terminal of the module. Otherwise, it will affect the normal operation of the module.
- During distance measurement, the area of the measured object should be no less than 0.5 square meters and the surface should be as flat as possible. Otherwise, the measurement result will be affected.
Application Scenarios
The HY-SRF05 has a wide range of applications!
For example:
Robot obstacle avoidance system: enables the car to automatically identify obstacles ahead and avoid them.
Intelligent parking system: detects whether the parking space is occupied and combines with LED lights for indication.
Automatic door control device: automatically opens the door when someone approaches.
Water level monitoring system: determines the water level in the tank by distance measurement.
Toy remote control car: enables automatic braking or steering.
Whether you are a student doing a course design, a maker presenting a project, or an electronics enthusiast working on home automation, the HY-SRF05 can handle it with ease!
In conclusion, the 5-Pin ultrasonic module HY-SRF05 is a “compact yet powerful” sensor. It is affordable, stable in performance, and easy to use. If you are looking for a reliable distance measurement module, HY-SRF05 is a good choice!
Relative Information
HY-SRF05 Ultrasonic Module Purchase Link
FAQ
1、How to check if your ultrasonic sensor is working?
To check if the ultrasonic sensor (such as HC-SR04 or HY-SRF05) is working properly:
1) Check the wiring: Ensure that VCC (5V), GND, Trig (trigger), and Echo are correctly connected.
2) Upload the test code: Use Arduino to send a 10μs trigger signal and read the Echo high level time to calculate the distance.
3) Observe the results:
Normal: Serial port displays a stable distance value (such as 15 cm).
Abnormal: Returns 0 (wiring/sensor problem), an extremely large value (signal loss), or garbled characters (interference/damage).
4) Quick test: Cover the sensor with your hand, the distance value should change. If there is no response, check the power supply or replace the sensor. If the problem persists, it may be that the sensor is damaged. It is recommended to replace it.
2、How long do ultrasonic sensors last?
The lifespan of ultrasonic sensors (such as HC-SR04/HY-SRF05) is usually 3-5 years or 500,000-1,000,000 distance measurements, depending on the usage environment. Frequent exposure to high temperatures, humidity or mechanical shocks will shorten the lifespan. Under normal conditions, they can work stably for a long time. If there is inaccurate distance measurement, abnormal signal or no response, it may be due to aging and requires replacement.
3、How do you clean an ultrasonic sensor?
The correct method for cleaning an ultrasonic sensor:
1) Power-off operation
First, disconnect the power supply to avoid the risk of short circuit.
2) Surface cleaning
Use a soft, slightly damp, lint-free cloth (such as a spectacle cloth) to gently wipe the sensor surface.
For stubborn stains, a small amount of isopropyl alcohol (with a concentration of less than 70%) can be used for auxiliary cleaning.
3) Matters need attention:
Do not use organic solvents (such as acetone) or corrosive cleaners.
Avoid scratching the sensor surface.
Do not immerse or rinse with water.
After cleaning, dry thoroughly before powering on.
4) Regular maintenance:
It is recommended to check and clean once every 3-6 months.
In industrial environments, this can be shortened to 1-2 months.
Note: Focus on cleaning the emission/reception holes during cleaning, as this is the key area that affects the measurement accuracy. If there is still abnormal measurement after cleaning, it may be a fault in the sensor that requires replacement.
4、What interferes with ultrasonic sensors?
Ultrasonic sensors are susceptible to the following disturbances:
① Surface dirt or obstruction (regular cleaning is required).
② Severe weather conditions such as strong winds and rain/fog.
③ Interference from other ultrasonic devices or metal reflections.
④ Electromagnetic interference (such as from high-power equipment).
⑤ Installation vibration or tilt. It is recommended to keep the sensor clean, stay away from interference sources, and install it stably. In necessary cases, choose anti-interference models.
5、Will two ultrasonic sensors interfere with each other?
They will interfere with each other! When two ultrasonic sensors are operating simultaneously, the following problems may occur:
1) Signal crosstalk: The sound waves of one sensor may be wrongly received by the other, resulting in incorrect distance measurement.
2) Measurement failure: The sound waves triggered simultaneously may cancel each other out or superimpose, affecting the detection of echoes.
Solutions:
- Delay the triggering time (such as more than 50ms apart).
- Physical isolation (spacing > 1 meter or installation at different angles).
- Work in alternate timing (alternately start).
- Select anti-interference models (such as sensors with encoded signals).
In industrial applications, it is recommended to use ultrasonic modules with synchronization functions or replace them with TOF (time of flight) sensors to avoid interference.
6、Can the ultrasonic sensor work in the dark?
It can be used in dark environments. Unlike proximity sensors that use lights or cameras, the ultrasonic sensor’s detection ability is not affected by dark conditions.
7、Can ultrasound penetrate walls?
The behavior of ultrasound is more like that of light rather than sound. For instance, music from a stereo system can fill an entire house. Ultrasound cannot penetrate solid surfaces (such as walls, floors, and ceilings), nor can it bypass corners.