SR-R
AI

The **SR-04** (commonly referred to as the HC-SR04) is an ultrasonic distance sensor used widely in robotics and electronics projects. It operates on the principle of **sonar**, using sound waves to determine the distance to an object.
---
### 1. Key Electronic Specifications
The performance of the sensor depends on these electrical parameters:
| Parameter | Specification |
| :--- | :--- |
| **Operating Voltage** | 5V DC |
| **Operating Current** | 15mA |
| **Working Frequency** | 40 kHz |
| **Max Range** | 4 meters |
| **Min Range** | 2 cm |
| **Measuring Angle** | 15 degrees |
| **Trigger Input Signal** | 10µs TTL pulse |
---
### 2. Pin Configuration
The sensor features a 4-pin interface for communication with microcontrollers (like Arduino or ESP32):
1. **VCC**: Power supply (5V).
2. **Trig (Trigger)**: Input pin. Sending a high pulse here initiates the measurement.
3. **Echo**: Output pin. This pin stays HIGH for the duration it takes for the sound wave to return.
4. **GND**: Ground.
---
### 3. Core Components
The board consists of several specialized electronic parts:
* **Ultrasonic Transmitter (T)**: A transducer that converts electrical energy into 40kHz sound pulses.
* **Ultrasonic Receiver (R)**: A transducer that detects the reflected sound waves and converts them back into electrical signals.
* **Control Circuitry**: Usually involves an integrated circuit (IC) like the **LM324** (Quad Operational Amplifier) to amplify the weak signal received by the receiver, and a microprocessor/timer to handle the logic.
---
### 4. Working Logic (Code Implementation)
To use the sensor, you must trigger it and then measure the timing of the pulse on the Echo pin.
```cpp
// Example Arduino Code Snippet
long duration;
int distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // Send 10us pulse
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Read time in microseconds
distance = duration * 0.034 / 2; // Calculate distance (Speed of sound = 340m/s)
```
---
### 5. Distance Calculation Formula
The distance is calculated based on the speed of sound ($v \approx 340\text{ m/s}$ or $0.034\text{ cm/µs}$):
$$\text{Distance} = \frac{\text{Time} \times \text{Speed of Sound}}{2}$$
*Note: We divide by 2 because the sound travels to the object and back.*
- ⤷How do I connect an HC-SR04 to an Arduino?
- ⤷ What are the common causes of inaccurate readings in ultrasonic sensors?
- ⤷ Is there a 3.3V version of the HC-SR04 for ESP32 or Raspberry Pi?