Description
HC-SR04 Ultrasonic Distance Sensor Module
The HC-SR04 module determines the distance to an object by sending an ultrasonic pulse and receiving a delayed reflection. Based on this delay, the device determines the presence of objects and the distance to them. The ultrasonic emitter sends 8 signals at a frequency of 40kHz, which will be reflected by objects and recorded with a microphone in this sensor module.
It can measure from 2 cm to 400 cm with an accuracy of 2 mm. It is an ideal ultrasonic module for distance measurement, proximity sensors, and ultrasonic detectors.
Technical Specification:
- Operating Voltage: 5V DC.
- Operating Current: Less than 15 mA.
- Range: 2 cm to 400 cm (0.79 inches to 13 feet).
- Accuracy: Around ±3 mm.
- Frequency: 40 kHz.
Pinouts:

Connection with Arduino:
Module |
Arduino UNO |
VCC |
5V |
Trig |
Pin 9 |
Echo |
Pin 10 |
GND |
GND |
Sample Code:
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
// Send a 10-microsecond pulse to the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin and calculate the distance
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.0343 / 2;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}