1. Introdución
The SainSmart HC-SR04 Ultrasonic Distance Sensor module is designed for precise non-contact distance measurement. It utilizes ultrasonic waves to determine the distance to an object, making it suitable for various applications such as robotics, obstacle avoidance, and level sensing. This module offers a measurement range from 2 cm to 400 cm with high accuracy.

Figura 1: Fronte view of the HC-SR04 Ultrasonic Distance Sensor, showing the two ultrasonic transducers and the module's pins.
2. Características do produto
- Vol. Operativotage: 5V DC
- Corrente de reposo: Menos de 2 mA
- Effective Angle: Menos de 15 graos
- Distancia de alcance: 2 cm a 400 cm
- Resolución: 0.3 cm
- Entrada de activación: 10us high-level signal
- Operación automática: Module automatically sends eight 40 kHz ultrasonic pulses.
3. Especificacións
| Dimensións do produto | 1.3 x 0.4 x 0.05 polgadas |
| Peso do elemento | 0.8 onzas |
| Número de modelo | HC-SR04 |
| Fonte de alimentación | 5V DC |
| Corrente Quiescente | <2 mA |
| Ángulo efectivo | <15 graos |
| Distancia de alcance | 2 cm - 400 cm |
| Resolución | 0.3 cm |
4. Pinout e conexións
The HC-SR04 module features four pins for connection to a microcontroller or other circuit:
- VCC: Power supply (5V DC).
- Trig (Trigger): Input pin to initiate the ultrasonic burst. A 10us high-level pulse is required.
- Eco: Output pin that goes high when the ultrasonic pulse is sent and stays high until the echo is received. The duration of this high-level signal is proportional to the distance.
- GND: Conexión a terra.

Figura 2: Atrás view of the HC-SR04 module, showing the electronic components and the four connection pins.
Ensure correct polarity when connecting VCC and GND to avoid damage to the module.
5. Configuración
To set up the HC-SR04 sensor for operation, follow these steps:
- Conexión de alimentación: Conecta o VCC pin to a 5V DC power source and the GND pin to the ground of your microcontroller or power supply.
- Trigger Pin Connection: Conecta o Disparador pin to a digital output pin on your microcontroller (e.g., Arduino, Raspberry Pi).
- Echo Pin Connection: Conecta o Eco pin to a digital input pin on your microcontroller.
- Montaxe: Securely mount the sensor in the desired location, ensuring a clear line of sight to the target object. Avoid mounting in areas with excessive vibrations or acoustic interference.
Nota: For microcontrollers operating at 3.3V (like some Raspberry Pi models), a voltage divider or level shifter may be required for the Echo pin to prevent damage, as the Echo pin outputs 5V.
6. Funcionamento
The HC-SR04 operates by emitting an ultrasonic sound wave and measuring the time it takes for the echo to return. The process is as follows:
- Activación: To initiate a measurement, the microcontroller sends a short high-level pulse (at least 10 microseconds) to the Disparador alfinete.
- Ultrasonic Burst: Upon receiving the trigger pulse, the HC-SR04 module automatically emits eight 40 kHz ultrasonic sound waves.
- Echo Reception: The module then waits for the echo of these sound waves. When an echo is detected, the Eco pin goes high.
- Duration Measurement: The microcontroller measures the duration for which the Eco pin remains high. This duration represents the time taken for the ultrasonic wave to travel from the sensor to the object and back.
- Cálculo de distancia: The distance to the object can be calculated using the following formula:
Distance (cm) = (Duration of high level on Echo pin (microseconds) * Speed of Sound (cm/µs)) / 2
The speed of sound in air is approximately 340 meters per second (0.034 cm per microsecond). Therefore, the formula simplifies to:
Distance (cm) = Duration (µs) / 58
(Alternatively, Distance (inches) = Duration (µs) / 148)
It is recommended to introduce a small delay (e.g., 60ms) between consecutive measurements to allow the ultrasonic waves to dissipate and prevent interference with subsequent readings.
7. Mantemento
The HC-SR04 module is a low-maintenance device. To ensure optimal performance and longevity:
- Manter limpo: Ensure the ultrasonic transducers are free from dust, dirt, or obstructions. Gently clean with a soft, dry cloth if necessary. Avoid using liquids or abrasive materials.
- Condicións ambientais: Operate the sensor within its specified temperature and humidity ranges. Avoid exposure to extreme temperatures, direct sunlight for prolonged periods, or high moisture environments.
- Protección física: Protect the module from physical impact or excessive force, which could damage the transducers or circuit board.
- Fonte de alimentación: Always use a stable 5V DC power supply. Fluctuations in voltage can affect performance or damage the module.
8 Solución de problemas
If you encounter issues with your HC-SR04 sensor, consider the following common problems and solutions:
- No Readings or Erratic Readings:
- Comproba as conexións: Verify that VCC, GND, Trig, and Echo pins are correctly wired and securely connected.
- Fonte de alimentación: Ensure the module is receiving a stable 5V DC power supply.
- Trigger Pulse: Confirm that the Trig pin is receiving a clean 10us high-level pulse. Incorrect pulse duration can lead to no or inaccurate readings.
- Echo Pin Reading: Ensure your microcontroller code is correctly measuring the pulse duration on the Echo pin.
- Interferencia: Ultrasonic sensors can be affected by other ultrasonic devices, strong air currents, or noisy environments. Try testing in a quiet area.
- Object Characteristics: Very soft, sound-absorbing materials (like fabric or wool) or very small/thin objects may not reflect enough sound for detection. Highly angled surfaces can also cause issues.
- Inaccurate Distance Readings:
- Speed of Sound: The speed of sound varies slightly with temperature and humidity. For highly precise applications, consider temperature compensation. The provided formula uses an average speed.
- Ángulo do feixe: The sensor has an effective angle of less than 15 degrees. Objects outside this cone may not be detected accurately or at all.
- Distancia mínima: The sensor has a minimum detection distance of 2cm. Objects closer than this may yield unreliable results.
- Distancia máxima: While rated up to 400cm, practical maximum range can be affected by object size, material, and environmental conditions.
- O módulo non responde:
- Ciclo de enerxía: Disconnect and reconnect power to the module.
- Voltage Compatibilidade: If using a 3.3V microcontroller, ensure proper voltage level shifting for the Echo pin.
- Danos: Inspect the module for any visible physical damage.
9. Garantía e soporte
SainSmart products are designed for reliability and performance. For specific warranty information, please refer to the documentation provided with your purchase or visit the official SainSmart website. For technical support, troubleshooting assistance, or inquiries about product functionality, please contact SainSmart customer service through their official channels.
Recursos en liña: Many online communities and forums dedicated to Arduino, Raspberry Pi, and electronics projects offer extensive resources and examples for using the HC-SR04 sensor. Searching for "HC-SR04 Arduino tutorial" or "HC-SR04 Raspberry Pi Python" can provide valuable code examples and project ideas.





