Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

How to Use HC-SR04 (SIM TEST): Examples, Pinouts, and Specs

Image of HC-SR04 (SIM TEST)
Cirkit Designer LogoDesign with HC-SR04 (SIM TEST) in Cirkit Designer

HC-SR04 Ultrasonic Distance Sensor Documentation

1. Introduction

The HC-SR04 is an ultrasonic distance sensor that measures the distance to an object by emitting ultrasonic waves and calculating the time it takes for the echo to return. This sensor is widely used in robotics and automation for applications such as obstacle detection, distance measurement, and level sensing. Its ability to provide accurate distance readings makes it a popular choice for projects involving autonomous vehicles, drones, and various other electronic devices.

Common Applications and Use Cases

  • Obstacle detection in robotics
  • Distance measurement for automation systems
  • Level sensing in tanks and containers
  • Proximity sensing in smart home devices
  • Object avoidance in mobile robots

2. Technical Specifications

Key Technical Details

Specification Value
Operating Voltage 5V DC
Current Consumption 15 mA (max)
Frequency 40 kHz
Measuring Range 2 cm to 400 cm
Accuracy ±3 mm
Beam Angle 15 degrees

Pin Configuration and Descriptions

Pin Number Pin Name Description
1 VCC Power supply (5V)
2 Trig Trigger pin for initiating measurement
3 Echo Echo pin for receiving the reflected signal
4 GND Ground connection

3. Usage Instructions

How to Use the HC-SR04 in a Circuit

  1. Wiring the Sensor:

    • Connect the VCC pin to a 5V power supply.
    • Connect the GND pin to the ground.
    • Connect the Trig pin to a digital output pin on your microcontroller (e.g., Arduino).
    • Connect the Echo pin to a digital input pin on your microcontroller.
  2. Basic Circuit Diagram:

    +5V ---- VCC (HC-SR04)
    GND ---- GND (HC-SR04)
    D2  ---- Trig (HC-SR04)
    D3  ---- Echo (HC-SR04)
    

Important Considerations and Best Practices

  • Ensure that the sensor is mounted securely and is not obstructed by any objects.
  • Avoid using the sensor in environments with high levels of noise, as this can affect accuracy.
  • The sensor should not be used in heavy rain or extreme temperatures, as this may damage it.
  • Always check the wiring before powering the circuit to prevent damage.

4. Example Code for Arduino UNO

Here is a simple example code to use the HC-SR04 with an Arduino UNO:

#define TRIG_PIN 2  // Trigger pin connected to digital pin 2
#define ECHO_PIN 3  // Echo pin connected to digital pin 3

void setup() {
  Serial.begin(9600); // Start serial communication
  pinMode(TRIG_PIN, OUTPUT); // Set trigger pin as output
  pinMode(ECHO_PIN, INPUT);  // Set echo pin as input
}

void loop() {
  long duration, distance;
  
  // Clear the trigger
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  
  // Set the trigger high for 10 microseconds
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  
  // Read the echo pin, return the sound wave travel time
  duration = pulseIn(ECHO_PIN, HIGH);
  
  // Calculate the distance (duration/2) * speed of sound (0.034 cm/us)
  distance = (duration * 0.034) / 2;
  
  // Print the distance to the Serial Monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  
  delay(1000); // Wait for a second before the next measurement
}

5. Troubleshooting and FAQs

Common Issues Users Might Face

  1. Inaccurate Distance Readings:

    • Ensure the sensor is not obstructed and is mounted correctly.
    • Check for any noise interference in the environment.
  2. No Response from the Sensor:

    • Verify the wiring connections and ensure the power supply is correct.
    • Check if the Arduino code is uploaded correctly.
  3. Sensor Not Powering On:

    • Confirm that the VCC pin is connected to a 5V power source.
    • Inspect for any physical damage to the sensor.

Solutions and Tips for Troubleshooting

  • Always use a multimeter to check voltage levels at the VCC and GND pins.
  • If using a breadboard, ensure that all connections are secure and not loose.
  • Test the sensor with a simple code to isolate issues related to the sensor itself.

By following this documentation, users can effectively utilize the HC-SR04 ultrasonic distance sensor in their projects, ensuring accurate distance measurements and reliable performance.

Explore Projects Built with HC-SR04 (SIM TEST)

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Arduino UNO-Based Ultrasonic Security System with SIM800L GSM Module
Image of Home security system: A project utilizing HC-SR04 (SIM TEST) in a practical application
This circuit features an Arduino UNO connected to an HC-SR04 ultrasonic sensor for distance measurement and a SIM800L GSM module for communication. The Arduino controls an LED, which lights up based on the distance detected by the ultrasonic sensor. When a certain distance threshold is exceeded, the Arduino uses the SIM800L module to make a phone call, indicating motion detection. A 48V to 5V converter supplies power to the SIM800L and the ultrasonic sensor.
Cirkit Designer LogoOpen Project in Cirkit Designer
STM32F103C8T6-Based Water Level Monitoring and Communication System with SIM900A and LoRa Connectivity
Image of water level: A project utilizing HC-SR04 (SIM TEST) in a practical application
This circuit features a microcontroller (STM32F103C8T6) interfaced with a SIM900A GSM module, an HC-SR04 ultrasonic sensor, a water level sensor, and a LoRa Ra-02 SX1278 module for long-range communication. The STM32F103C8T6 is configured to communicate with the GSM module and LoRa module via serial connections, and it reads data from the ultrasonic and water level sensors. An FTDI Programmer is connected for programming and serial communication with the microcontroller.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO-Based Ultrasonic Distance Sensor with OLED Display and SIM900A Communication
Image of SENSOR: A project utilizing HC-SR04 (SIM TEST) in a practical application
This circuit is a distance measurement and communication system using an Arduino UNO, an ultrasonic sensor, an OLED display, and a SIM900A module. The ultrasonic sensor measures the distance to an object, which is then displayed on the OLED screen and transmitted via the SIM900A module. The system is powered by a 18650 Li-ion battery.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO-Based Ultrasonic Distance Measurement System with GSM and LCD Display
Image of Arduino projects : A project utilizing HC-SR04 (SIM TEST) in a practical application
This circuit uses an Arduino UNO to interface with an HC-SR04 ultrasonic sensor for distance measurement, a 16x2 I2C LCD for displaying information, a piezo buzzer for audio alerts, and a SIM900A module for GSM communication. The 5V adapter powers the SIM900A module, while the Arduino provides power to the other components.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with HC-SR04 (SIM TEST)

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Home security system: A project utilizing HC-SR04 (SIM TEST) in a practical application
Arduino UNO-Based Ultrasonic Security System with SIM800L GSM Module
This circuit features an Arduino UNO connected to an HC-SR04 ultrasonic sensor for distance measurement and a SIM800L GSM module for communication. The Arduino controls an LED, which lights up based on the distance detected by the ultrasonic sensor. When a certain distance threshold is exceeded, the Arduino uses the SIM800L module to make a phone call, indicating motion detection. A 48V to 5V converter supplies power to the SIM800L and the ultrasonic sensor.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of water level: A project utilizing HC-SR04 (SIM TEST) in a practical application
STM32F103C8T6-Based Water Level Monitoring and Communication System with SIM900A and LoRa Connectivity
This circuit features a microcontroller (STM32F103C8T6) interfaced with a SIM900A GSM module, an HC-SR04 ultrasonic sensor, a water level sensor, and a LoRa Ra-02 SX1278 module for long-range communication. The STM32F103C8T6 is configured to communicate with the GSM module and LoRa module via serial connections, and it reads data from the ultrasonic and water level sensors. An FTDI Programmer is connected for programming and serial communication with the microcontroller.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of SENSOR: A project utilizing HC-SR04 (SIM TEST) in a practical application
Arduino UNO-Based Ultrasonic Distance Sensor with OLED Display and SIM900A Communication
This circuit is a distance measurement and communication system using an Arduino UNO, an ultrasonic sensor, an OLED display, and a SIM900A module. The ultrasonic sensor measures the distance to an object, which is then displayed on the OLED screen and transmitted via the SIM900A module. The system is powered by a 18650 Li-ion battery.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Arduino projects : A project utilizing HC-SR04 (SIM TEST) in a practical application
Arduino UNO-Based Ultrasonic Distance Measurement System with GSM and LCD Display
This circuit uses an Arduino UNO to interface with an HC-SR04 ultrasonic sensor for distance measurement, a 16x2 I2C LCD for displaying information, a piezo buzzer for audio alerts, and a SIM900A module for GSM communication. The 5V adapter powers the SIM900A module, while the Arduino provides power to the other components.
Cirkit Designer LogoOpen Project in Cirkit Designer