

The HC-SR04 Ultrasonic Sensor, manufactured by FKR (Part ID: HCSR04), is a highly versatile and widely used distance measurement module. It operates by emitting ultrasonic waves and calculating the time it takes for the echo to return after bouncing off an object. This time is then used to determine the distance to the object with high precision.








The HC-SR04 is designed for ease of use and reliable performance. 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° |
| Accuracy | ±3 mm |
| Signal Frequency | 40 kHz |
| Dimensions | 45 mm x 20 mm x 15 mm |
The HC-SR04 has four pins, as described in the table below:
| Pin | Name | Description |
|---|---|---|
| 1 | VCC | Power supply pin. Connect to a 5V DC source. |
| 2 | Trig | Trigger pin. A 10 µs HIGH pulse initiates the ultrasonic burst. |
| 3 | Echo | Echo pin. Outputs a pulse proportional to the distance of the detected object. |
| 4 | GND | Ground pin. Connect to the ground of the power supply. |
The HC-SR04 is simple to integrate into a circuit and can be used with microcontrollers like the Arduino UNO. Below are the steps to use the sensor:
Below is an example Arduino sketch to measure distance using the HC-SR04:
// Define pins for the HC-SR04 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 the trigPin as an output and echoPin as an input
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// Send a 10 µs HIGH pulse to the trigPin to trigger the sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the duration of the HIGH pulse on the echoPin
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance in centimeters
long distance = duration * 0.034 / 2;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Wait for a short period before the next measurement
delay(500);
}
No Output or Incorrect Distance Readings
Echo Pin Always HIGH or LOW
Inconsistent Measurements
Q: Can the HC-SR04 measure distances below 2 cm?
A: No, the minimum measurable distance is 2 cm. Objects closer than this may not be detected accurately.
Q: Can I use the HC-SR04 with a 3.3V microcontroller?
A: Yes, but you must use a level shifter or resistor divider to safely connect the Echo pin to the microcontroller.
Q: What is the maximum range of the HC-SR04?
A: The sensor can measure distances up to 400 cm (4 meters) under ideal conditions.
Q: How can I improve measurement accuracy?
A: Use the sensor in a controlled environment with minimal obstructions and ensure proper alignment with the target object.