HC-R
AI

It appears you are referring to the **HC-SR04**, which is one of the most popular ultrasonic distance sensors used in electronics and robotics.
---
## 1. Core Component Overview
The HC-SR04 is a module that uses sonar to determine the distance to an object. It consists of four main electronic sections:
| Component | Function |
| :--- | :--- |
| **Ultrasonic Transmitter** | Converts electrical signals into 40kHz sound waves. |
| **Ultrasonic Receiver** | Listens for the reflected echo of the sound waves. |
| **Control Circuit** | Manages the timing, signal processing, and calculation. |
| **Pin Header** | 4-pin interface (VCC, Trig, Echo, GND). |
---
## 2. Technical Specifications
Understanding the electronic limits is crucial for preventing damage to the module.
| Parameter | Specification |
| :--- | :--- |
| **Operating Voltage** | DC 5V |
| **Operating Current** | 15mA |
| **Operating Frequency** | 40Hz |
| **Max Range** | 4m |
| **Min Range** | 2cm |
| **Ranging Angle** | 15 degrees |
| **Input Trigger Signal** | 10µs TTL pulse |
---
## 3. How the Electronics Work (The Sequence)
The module operates through a specific electronic handshake with a microcontroller (like an Arduino):
1. **Triggering:** The microcontroller sends a high pulse (5V) to the **Trig** pin for at least 10 microseconds.
2. **Sonic Burst:** The internal control circuit emits eight pulses of ultrasonic sound at 40 kHz.
3. **Echo High:** The **Echo** pin goes "HIGH" the moment the sound is sent.
4. **Reflection:** When the sound hits an object and returns to the receiver, the **Echo** pin goes "LOW."
5. **Calculation:** The distance is calculated based on the duration the Echo pin remained HIGH.
### The Formula
To calculate the distance in centimeters:
`Distance = (Time x Speed of Sound) / 2`
*(We divide by 2 because the sound travels to the object and back).*
---
## 4. Basic Wiring Diagram (Code Style)
To connect this to a microcontroller, use the following logic:
```cpp
// Typical Arduino Pin Definition
#define trigPin 9
#define echoPin 10
void setup() {
pinMode(trigPin, OUTPUT); // Sends the pulse
pinMode(echoPin, INPUT); // Receives the echo
}
```
---
- ⤷
How do I wire the HC-SR04 to a 3.3V device like an ESP32 or Raspberry Pi?
- ⤷ What are the most common causes of inaccurate readings in ultrasonic sensors?
- ⤷ Is there a waterproof version of the HC-SR04 for outdoor use?