Skip to Content

Ultrasonic HC-SR04 Module Distance Sensor

An ultrasonic sensor is essential for determining the distance between a robot and a target. It plays a crucial role in various robotic projects, including maze-solving robots, by helping detect walls and providing data to control movement. The most commonly used ultrasonic sensor is the HC-SR04, which employs sonar technology to calculate the distance to an object.

Package Includes:

  • 1 x Ultrasonic HC-SR04 Module Distance Sensor

Features:

  • Supply Voltage: 5V (DC) (Note: This version works at 5V; other versions that work from 3V to 5V are available on our website)

  • Supply Current: 15mA

  • Output: 0–5V (High when obstacle detected within range)

  • Beam Angle: Max 15 degrees

  • Distance Range: 2cm – 400cm

  • Accuracy: 0.3cm

  • Communication: Positive TTL pulse

Description:

The HC-SR04 ultrasonic sensor calculates the distance to an object by emitting ultrasonic waves and measuring how long it takes for the echo to return. With a measurement range of 2cm to 400cm (0.8 to 157 inches) and an accuracy of 0.3cm (0.1 inch), this sensor is widely used in hobbyist robotics projects. It includes an ultrasonic transmitter and receiver module.

Principle of Work:

Similar to SONAR and RADAR systems, the HC-SR04 sensor works by emitting high-frequency sound (ultrasound). The sound waves bounce off an object and return to the sensor, where the time taken for the echo to return is measured. The distance is calculated using the time taken and the speed of sound.

The formula to calculate the distance is:

Distance (cm) = (Speed of Sound (cm/s) × Time (s)) / 2

At 20°C, the speed of sound is approximately 343 m/s. Given that the sound waves travel to the object and back, we divide the result by 2.

Pinout of the HC-SR04 Module:

  • VCC: Powers the sensor (5V)

  • Trig: Trigger input pin (initiates ultrasonic pulse)

  • Echo: Echo output pin (receives the reflected pulse)

  • GND: Common ground

Applications:

  • Anti-collision detection in robots

  • People and presence detection

  • Box sorting in automated systems

  • Control of trash collection vehicles

  • Pallet detection for forklifts

  • Bottle counting in drink filling machines

Circuit Diagram:

To interface the HC-SR04 with an Arduino, connect the following:

  • VCC to 5V on the Arduino

  • Trig to Pin 11 on the Arduino

  • Echo to Pin 12 on the Arduino

  • GND to GND on the Arduino

Code Example:

The code below demonstrates how to use the HC-SR04 to measure distance using an Arduino:

int trigPin = 11; // Trigger Pin int echoPin = 12; // Echo Pin long duration, cm, inches; void setup() { Serial.begin(9600); // Start serial communication pinMode(trigPin, OUTPUT); // Set the trig pin as output pinMode(echoPin, INPUT); // Set the echo pin as input } void loop() { // Send a short LOW pulse to clean the previous HIGH pulse digitalWrite(trigPin, LOW); delayMicroseconds(5); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Read the time taken for the echo to return duration = pulseIn(echoPin, HIGH); // Calculate the distance in centimeters and inches cm = (duration / 2) / 29.1; inches = (duration / 2) / 74; // Print the distance to the Serial Monitor Serial.print(inches); Serial.print(" in, "); Serial.print(cm); Serial.print(" cm"); Serial.println(); delay(250); // Delay before the next measurement }

Technical Details:

  • Operating Voltage: 5V DC

  • Operating Current: 15mA

  • Operating Frequency: 40KHz

  • Min Range: 2cm (1 inch)

  • Max Range: 400cm (13 feet)

  • Accuracy: 3mm

  • Measuring Angle: <15°

  • Dimensions: 45 x 20 x 15mm

Comparisons with PIR Sensor:

  • Detection Method:

    • PIR sensors detect motion by sensing infrared radiation from objects.

    • Ultrasonic sensors detect objects by emitting sound waves and measuring the time it takes for the waves to return.

  • Power Consumption:

    • PIR sensors tend to consume less power than ultrasonic sensors.

  • Detection Range:

    • Ultrasonic sensors generally have a limited detection range compared to PIR sensors, which detect movement within a wide range based on heat emissions.

Both types of sensors are useful for different applications depending on the need for detecting proximity (ultrasonic) or motion (PIR).

12.00 AED 12.00 AED Tax Included
12.00 AED Tax Included

Not Available For Sale

This combination does not exist.

Terms and Conditions
30-day money-back guarantee
Shipping: 2-3 Business Days