[match_prediction match_id="3"]

HC-SR04 Ultrasonic Distance Sensor Module

  1. Operating Voltage: 5 V
  2. Sonar Sensing Range: 2-400 cm
  3. Max. Sensing Range: 450 cm
  4. Frequency: 40 kHz

 

SKU: AB043 Categories: ,

50,00 EGP

3 People watching this product now!

Frequently Bought Together

50,00 EGP
25,00 EGP
75,00 EGP
For 2 items

Description

The HC-SR04 is an ultrasonic distance sensor module that measures the distance to an object using sound waves. It provides accurate and reliable distance measurements, making it ideal for robotics, obstacle avoidance systems, and other applications requiring distance sensing.

Key Features:

  • Measurement Range: 2 cm to 400 cm (2m)
  • Accuracy: Up to 3mm
  • Operating Voltage: 5V (compatible with most microcontrollers like Arduino, Raspberry Pi, etc.)
  • Operating Frequency: 40kHz (ultrasonic sound wave frequency)
  • Signal Type: Digital Output (Echo and Trigger pins for distance measurement)
  • Current Consumption: Low power consumption, typically around 15mA when idle and 20mA when active
  • Mounting Type: Easy to mount on robots or other projects with simple pin connections
  • Interface: 4-pin (VCC, GND, Trigger, Echo)

Pinout:

  1. VCC: Power supply pin (5V)
  2. GND: Ground pin
  3. Trigger (Trig): Sends a pulse to initiate the measurement (usually a 10us HIGH pulse)
  4. Echo: Outputs the time it takes for the ultrasonic sound wave to return (used to calculate distance)

Applications:

  • Robotics: Used for obstacle detection and avoidance in autonomous robots.
  • Distance Measurement: Ideal for measuring distances in projects requiring accurate and reliable distance readings.
  • Parking Sensors: Used in automotive applications for proximity detection.
  • Security Systems: Can be used for motion detection or proximity sensing in various security setups.
  • Automation: Helps with automatic systems that require distance sensing or positioning, such as object detection and counting.

Benefits:

  • Simple to Use: Easy to interface with most microcontrollers like Arduino, Raspberry Pi, and others.
  • Affordable: Provides accurate distance measurements at an affordable price, making it perfect for hobbyists and DIY projects.
  • High Accuracy: Offers precision with distances as close as 2cm and up to 400cm, making it suitable for a wide range of applications.
  • Low Power Consumption: Efficient enough to be used in battery-powered projects, like mobile robots or drones.

The HC-SR04 Ultrasonic Distance Sensor Module is a reliable and cost-effective solution for distance measurement and obstacle detection, making it a popular choice for robotics, automation, and other electronic projects.

🔌
Pin Connections
1 Table
Pin Connections Table 1
Board NameComponent / SensorConnection Details
Arduino UnoHC-SR04VCC->5V, GND->GND, TRIG->D9, ECHO->D10
Arduino NanoHC-SR04VCC->5V, GND->GND, TRIG->D9, ECHO->D10
Arduino MegaHC-SR04VCC->5V, GND->GND, TRIG->D9, ECHO->D10
ESP32HC-SR04VCC->5V, GND->GND, TRIG->GPIO5, ECHO->GPIO18
ESP8266HC-SR04VCC->5V, GND->GND, TRIG->GPIO5 (D1), ECHO->GPIO4 (D2)
STM32HC-SR04VCC->5V, GND->GND, TRIG->PA0, ECHO->PA1
Raspberry Pi PicoHC-SR04VCC->5V, GND->GND, TRIG->GP0, ECHO->GP1
Generic C/C++HC-SR04VCC->5V, GND->GND, TRIG->PIN_TRIG, ECHO->PIN_ECHO (define accordingly)
📟
HC-SR04 Ultrasonic Distance Sensor
8 Examples • C/C++ | Boards: Arduino Uno, Arduino Nano, Arduino Mega, ESP32, ESP8266, STM32, Raspberry Pi Pico, Generic C/C++
HC-SR04 on Arduino Uno
HC-SR04 on Arduino Nano
HC-SR04 on Arduino Mega
HC-SR04 on ESP32
HC-SR04 on ESP8266
HC-SR04 on STM32
HC-SR04 on Raspberry Pi Pico
HC-SR04 on Generic C/C++
Code Comments:
Arduino Uno code for HC-SR04 using NewPing library. Pin connections: TRIG D9, ECHO D10.
📄 File: hc-sr04_on_arduino_uno.inoArduino Uno
706 characters
1/*
2 * ekostra.com
3 * ekostra electronics store in egypt
4 */
5
6#include <NewPing.h>
7
8#define TRIGGER_PIN 9 // D9
9#define ECHO_PIN 10 // D10
10#define MAX_DISTANCE 200 // Maximum distance (cm)
11
12NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
13
14void setup() {
15 Serial.begin(9600);
16 Serial.println("HC-SR04 Ultrasonic Sensor on Arduino Uno");
17}
18
19void loop() {
20 // Wait for stable reading
21 delay(50);
22
23 // Get distance in cm
24 unsigned int distance = sonar.ping_cm();
25
26 // Print result
27 if (distance == 0) {
28 Serial.println("Out of range");
29 } else {
30 Serial.print("Distance: ");
31 Serial.print(distance);
32 Serial.println(" cm");
33 }
34
35 // Wait before next reading
36 delay(500);
37}
Code Comments:
Arduino Nano code for HC-SR04 using NewPing library. Pin connections: TRIG D9, ECHO D10.
📄 File: hc-sr04_on_arduino_nano.inoESP8266
572 characters
1/*
2 * ekostra.com
3 * ekostra electronics store in egypt
4 */
5
6#include <NewPing.h>
7
8#define TRIGGER_PIN 9 // D9
9#define ECHO_PIN 10 // D10
10#define MAX_DISTANCE 200
11
12NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
13
14void setup() {
15 Serial.begin(9600);
16 Serial.println("HC-SR04 Ultrasonic Sensor on Arduino Nano");
17}
18
19void loop() {
20 delay(50);
21 unsigned int distance = sonar.ping_cm();
22 if (distance == 0) {
23 Serial.println("Out of range");
24 } else {
25 Serial.print("Distance: ");
26 Serial.print(distance);
27 Serial.println(" cm");
28 }
29 delay(500);
30}
Code Comments:
Arduino Mega code for HC-SR04 using NewPing library. Pin connections: TRIG D9, ECHO D10.
📄 File: hc-sr04_on_arduino_mega.inoArduino Mega
572 characters
1/*
2 * ekostra.com
3 * ekostra electronics store in egypt
4 */
5
6#include <NewPing.h>
7
8#define TRIGGER_PIN 9 // D9
9#define ECHO_PIN 10 // D10
10#define MAX_DISTANCE 200
11
12NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
13
14void setup() {
15 Serial.begin(9600);
16 Serial.println("HC-SR04 Ultrasonic Sensor on Arduino Mega");
17}
18
19void loop() {
20 delay(50);
21 unsigned int distance = sonar.ping_cm();
22 if (distance == 0) {
23 Serial.println("Out of range");
24 } else {
25 Serial.print("Distance: ");
26 Serial.print(distance);
27 Serial.println(" cm");
28 }
29 delay(500);
30}
Code Comments:
ESP32 code for HC-SR04 using NewPing library. Pin connections: TRIG GPIO5, ECHO GPIO18.
📄 File: hc-sr04_on_esp32.inoESP32
573 characters
1/*
2 * ekostra.com
3 * ekostra electronics store in egypt
4 */
5
6#include <NewPing.h>
7
8#define TRIGGER_PIN 5 // GPIO5
9#define ECHO_PIN 18 // GPIO18
10#define MAX_DISTANCE 200
11
12NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
13
14void setup() {
15 Serial.begin(115200);
16 Serial.println("HC-SR04 Ultrasonic Sensor on ESP32");
17}
18
19void loop() {
20 delay(50);
21 unsigned int distance = sonar.ping_cm();
22 if (distance == 0) {
23 Serial.println("Out of range");
24 } else {
25 Serial.print("Distance: ");
26 Serial.print(distance);
27 Serial.println(" cm");
28 }
29 delay(500);
30}
Code Comments:
ESP8266 code for HC-SR04 using NewPing library. Pin connections: TRIG GPIO5 (D1), ECHO GPIO4 (D2).
📄 File: hc-sr04_on_esp8266.inoESP8266
584 characters
1/*
2 * ekostra.com
3 * ekostra electronics store in egypt
4 */
5
6#include <NewPing.h>
7
8#define TRIGGER_PIN 5 // GPIO5 (D1)
9#define ECHO_PIN 4 // GPIO4 (D2)
10#define MAX_DISTANCE 200
11
12NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
13
14void setup() {
15 Serial.begin(115200);
16 Serial.println("HC-SR04 Ultrasonic Sensor on ESP8266");
17}
18
19void loop() {
20 delay(50);
21 unsigned int distance = sonar.ping_cm();
22 if (distance == 0) {
23 Serial.println("Out of range");
24 } else {
25 Serial.print("Distance: ");
26 Serial.print(distance);
27 Serial.println(" cm");
28 }
29 delay(500);
30}
Code Comments:
STM32 code for HC-SR04 using NewPing library (Arduino core). Pin connections: TRIG PA0, ECHO PA1.
📄 File: hc-sr04_on_stm32.inoSTM32
556 characters
1/*
2 * ekostra.com
3 * ekostra electronics store in egypt
4 */
5
6#include <NewPing.h>
7
8#define TRIGGER_PIN PA0
9#define ECHO_PIN PA1
10#define MAX_DISTANCE 200
11
12NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
13
14void setup() {
15 Serial.begin(115200);
16 Serial.println("HC-SR04 Ultrasonic Sensor on STM32");
17}
18
19void loop() {
20 delay(50);
21 unsigned int distance = sonar.ping_cm();
22 if (distance == 0) {
23 Serial.println("Out of range");
24 } else {
25 Serial.print("Distance: ");
26 Serial.print(distance);
27 Serial.println(" cm");
28 }
29 delay(500);
30}
Code Comments:
Raspberry Pi Pico code for HC-SR04 using NewPing library (Arduino-pico core). Pin connections: TRIG GP0, ECHO GP1.
📄 File: hc-sr04_on_raspberry_pi_pico.inoRaspberry Pi Pico
580 characters
1/*
2 * ekostra.com
3 * ekostra electronics store in egypt
4 */
5
6#include <NewPing.h>
7
8#define TRIGGER_PIN 0 // GP0
9#define ECHO_PIN 1 // GP1
10#define MAX_DISTANCE 200
11
12NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
13
14void setup() {
15 Serial.begin(115200);
16 Serial.println("HC-SR04 Ultrasonic Sensor on Raspberry Pi Pico");
17}
18
19void loop() {
20 delay(50);
21 unsigned int distance = sonar.ping_cm();
22 if (distance == 0) {
23 Serial.println("Out of range");
24 } else {
25 Serial.print("Distance: ");
26 Serial.print(distance);
27 Serial.println(" cm");
28 }
29 delay(500);
30}
Code Comments:
Generic C++ implementation for HC-SR04, without platform-specific libraries. Users must implement pin I/O functions.
📄 File: hc-sr04_on_generic_c/c++.cppGeneric C/C++
1793 characters
1/*
2 * ekostra.com
3 * ekostra electronics store in egypt
4 */
5
6// Generic C++ code for HC-SR04 (platform-independent)
7// User must define TRIGGER_PIN and ECHO_PIN according to platform
8
9#include <chrono>
10#include <thread>
11#include <iostream>
12
13// Assume these are defined externally for the specific platform
14// #define TRIGGER_PIN 9
15// #define ECHO_PIN 10
16
17// Simulated functions for demonstration
18void digitalWrite(int pin, int value) {
19 // Platform-specific implementation
20 std::cout << "Writing " << value << " to pin " << pin << std::endl;
21}
22
23int digitalRead(int pin) {
24 // Platform-specific implementation
25 // Simulate returning echo
26 return 1;
27}
28
29void delayMicroseconds(int us) {
30 std::this_thread::sleep_for(std::chrono::microseconds(us));
31}
32
33void delay(int ms) {
34 std::this_thread::sleep_for(std::chrono::milliseconds(ms));
35}
36
37int pulseIn(int pin, int state) {
38 // Simulate pulse measurement
39 // In real implementation, measure time
40 return 500; // dummy value
41}
42
43void setup() {
44 // Initialize platform
45 std::cout << "HC-SR04 Ultrasonic Sensor on Generic C/C++" << std::endl;
46}
47
48void loop() {
49 // Send trigger pulse
50 digitalWrite(TRIGGER_PIN, LOW);
51 delayMicroseconds(2);
52 digitalWrite(TRIGGER_PIN, HIGH);
53 delayMicroseconds(10);
54 digitalWrite(TRIGGER_PIN, LOW);
55
56 // Measure echo duration
57 long duration = pulseIn(ECHO_PIN, HIGH);
58
59 // Calculate distance (cm)
60 float distance = (duration * 0.0343) / 2.0;
61
62 // Print result
63 if (distance > 200 || distance < 2) {
64 std::cout << "Out of range" << std::endl;
65 } else {
66 std::cout << "Distance: " << distance << " cm" << std::endl;
67 }
68
69 delay(500);
70}
71
72int main() {
73 setup();
74 while (true) {
75 loop();
76 }
77 return 0;
78}
Example project for HC-SR04 ultrasonic distance sensor module, with implementations for multiple boards using the NewPing library.
[acf_vc_integrator get_field_data_from="" field_group="25154" field_from_25154="field_694d5bea250d3" show_label="default" align="default" gallery_columns="" gm_show_placecard="default" gm_map_type_control="default" gm_fullscreen_control="default" gm_street_view_control="default" gm_zoom_control="default" gm_scale="default" hidden_field_name="ARDUINO CODE"]
هذا الوصف والمواصفات تمت كتابته بمساعدة الذكاء الاصطناعي، يُرجى مراجعته قبل الشراء.
برجاء تأكيد الطلب على الواتساب للتأكد من توفر المخزون قبل الدفع

Specification

General

WeightWeight9,0000 g
modelHC-SR04
operating-voltage-vdc5
average-current-consumption-ma2
frequencyhz40000
sensing-angle15°
max-sensing-distance-cm450
sensor-cover-dia-mm16
pcb-size-l-x-w-mm45 x 20

Customer Reviews