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

How to Use Schematic HC-SR04: Examples, Pinouts, and Specs

Image of Schematic HC-SR04
Cirkit Designer LogoDesign with Schematic HC-SR04 in Cirkit Designer

Introduction

The HC-SR04 is an ultrasonic distance sensor that uses sonar to measure distances. It emits ultrasonic waves and measures the time it takes for the echo to return, allowing it to calculate the distance to an object. This sensor is widely used in robotics, automation, and IoT applications for tasks such as obstacle detection, distance measurement, and object tracking. Its affordability, ease of use, and accuracy make it a popular choice for hobbyists and professionals alike.

Explore Projects Built with Schematic HC-SR04

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 Distance Measurement with HC-SR04 and Bluetooth Communication via HC-05
Image of hc sr`: A project utilizing Schematic HC-SR04 in a practical application
This circuit features an Arduino UNO microcontroller interfaced with an HC-SR04 Ultrasonic Sensor and an HC-05 Bluetooth module. The Arduino is configured to trigger the ultrasonic sensor to measure distance and communicate the data wirelessly via the HC-05 module. Power is supplied to both the sensor and the Bluetooth module from the Arduino's 5V output, and ground connections are shared among all components.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino Mega 2560 Bluetooth-Controlled Ultrasonic Distance Measurement
Image of circuitcycle: A project utilizing Schematic HC-SR04 in a practical application
This circuit features an Arduino Mega 2560 microcontroller interfaced with an HC-05 Bluetooth Module and an HC-SR04 Ultrasonic Sensor. The HC-05 is powered by the Arduino's VIN pin and is grounded to the Arduino's GND, enabling wireless communication capabilities. The HC-SR04 is powered by the Arduino's 5V output and uses two digital PWM pins (D7 for TRIG and D6 for ECHO) to measure distances via ultrasonic waves.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO Controlled Multi-Sensor Ultrasonic Distance Measurement System
Image of Breadboard: A project utilizing Schematic HC-SR04 in a practical application
This circuit consists of an Arduino UNO microcontroller connected to four HC-SR04 ultrasonic sensors. The Arduino controls the sensors by triggering ultrasonic pulses and measuring the time taken for the echoes to return, which allows it to calculate distances to nearby objects. The circuit is likely designed for applications such as obstacle detection or range finding in robotics or automation systems.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino Nano and ATtiny-Powered Ultrasonic Distance Measurement System
Image of ultrasound: A project utilizing Schematic HC-SR04 in a practical application
This circuit appears to be a sensor-based system that utilizes an Arduino Nano and an ATtiny microcontroller. The HC-SR04 Ultrasonic Sensor is likely used for distance measurement, with its TRIG and ECHO pins controlled by the ATtiny. A potentiometer is included, possibly for adjusting a threshold or calibration, and a resistor may be part of a pull-up/down configuration or for signal conditioning.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with Schematic HC-SR04

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 hc sr`: A project utilizing Schematic HC-SR04 in a practical application
Arduino UNO Based Ultrasonic Distance Measurement with HC-SR04 and Bluetooth Communication via HC-05
This circuit features an Arduino UNO microcontroller interfaced with an HC-SR04 Ultrasonic Sensor and an HC-05 Bluetooth module. The Arduino is configured to trigger the ultrasonic sensor to measure distance and communicate the data wirelessly via the HC-05 module. Power is supplied to both the sensor and the Bluetooth module from the Arduino's 5V output, and ground connections are shared among all components.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of circuitcycle: A project utilizing Schematic HC-SR04 in a practical application
Arduino Mega 2560 Bluetooth-Controlled Ultrasonic Distance Measurement
This circuit features an Arduino Mega 2560 microcontroller interfaced with an HC-05 Bluetooth Module and an HC-SR04 Ultrasonic Sensor. The HC-05 is powered by the Arduino's VIN pin and is grounded to the Arduino's GND, enabling wireless communication capabilities. The HC-SR04 is powered by the Arduino's 5V output and uses two digital PWM pins (D7 for TRIG and D6 for ECHO) to measure distances via ultrasonic waves.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Breadboard: A project utilizing Schematic HC-SR04 in a practical application
Arduino UNO Controlled Multi-Sensor Ultrasonic Distance Measurement System
This circuit consists of an Arduino UNO microcontroller connected to four HC-SR04 ultrasonic sensors. The Arduino controls the sensors by triggering ultrasonic pulses and measuring the time taken for the echoes to return, which allows it to calculate distances to nearby objects. The circuit is likely designed for applications such as obstacle detection or range finding in robotics or automation systems.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of ultrasound: A project utilizing Schematic HC-SR04 in a practical application
Arduino Nano and ATtiny-Powered Ultrasonic Distance Measurement System
This circuit appears to be a sensor-based system that utilizes an Arduino Nano and an ATtiny microcontroller. The HC-SR04 Ultrasonic Sensor is likely used for distance measurement, with its TRIG and ECHO pins controlled by the ATtiny. A potentiometer is included, possibly for adjusting a threshold or calibration, and a resistor may be part of a pull-up/down configuration or for signal conditioning.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications:

  • Obstacle detection in robotics
  • Distance measurement in automation systems
  • Liquid level measurement
  • Proximity sensing in IoT devices
  • Parking assistance systems

Technical Specifications

The HC-SR04 sensor operates by emitting ultrasonic waves at a frequency of 40 kHz and measuring the time it takes for the echo to return. Below are its key technical details:

Parameter Value
Operating Voltage 5V DC
Operating Current 15 mA (typical)
Operating Frequency 40 kHz
Measuring Range 2 cm to 400 cm
Measuring Angle 15°
Resolution 0.3 cm
Trigger Input Signal 10 µs TTL pulse
Echo Output Signal TTL pulse proportional to distance
Dimensions 45 mm x 20 mm x 15 mm

Pin Configuration and Descriptions

The HC-SR04 sensor has four pins, as described in the table below:

Pin Name Description
1 VCC Power supply pin. Connect to 5V DC.
2 Trig Trigger pin. Send a 10 µs HIGH pulse to initiate distance measurement.
3 Echo Echo pin. Outputs a HIGH pulse whose duration corresponds to the measured distance.
4 GND Ground pin. Connect to the ground of the power supply.

Usage Instructions

How to Use the HC-SR04 in a Circuit

  1. Power the Sensor: Connect the VCC pin to a 5V power supply and the GND pin to ground.
  2. Trigger the Sensor: Send a 10 µs HIGH pulse to the Trig pin to initiate a measurement.
  3. Read the Echo: Measure the duration of the HIGH pulse on the Echo pin. The duration is proportional to the distance of the object.
  4. Calculate Distance: Use the formula below to calculate the distance: [ \text{Distance (cm)} = \frac{\text{Pulse Duration (µs)}}{58} ] Alternatively, for distance in inches: [ \text{Distance (in)} = \frac{\text{Pulse Duration (µs)}}{148} ]

Important Considerations and Best Practices

  • Ensure the sensor is mounted securely and aligned properly for accurate measurements.
  • Avoid placing the sensor near ultrasonic noise sources, as they may interfere with its operation.
  • Use a capacitor (e.g., 10 µF) across the VCC and GND pins to stabilize the power supply.
  • The sensor has a minimum range of 2 cm. Objects closer than this may not be detected accurately.
  • For best results, ensure the object being measured has a flat, hard surface to reflect the ultrasonic waves.

Example: Using HC-SR04 with Arduino UNO

Below is an example code to interface the HC-SR04 with an Arduino UNO:

// Define pins for the HC-SR04 sensor
const int trigPin = 9;  // Trig 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 trigPin as output and echoPin as input
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  // Send a 10 µs HIGH pulse to the Trig pin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Measure the duration of the HIGH pulse on the Echo pin
  long duration = pulseIn(echoPin, HIGH);

  // Calculate the distance in centimeters
  float distance = duration / 58.0;

  // 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(100);
}

Notes:

  • Ensure the Trig and Echo pins are connected to the correct digital pins on the Arduino.
  • Use a resistor divider or logic level shifter if interfacing with a 3.3V microcontroller.

Troubleshooting and FAQs

Common Issues and Solutions

  1. No Output or Incorrect Readings:

    • Ensure the sensor is powered with 5V and the connections are secure.
    • Verify that the Trig pin is receiving a 10 µs HIGH pulse.
    • Check for obstacles or noise sources that may interfere with the ultrasonic waves.
  2. Unstable or Fluctuating Measurements:

    • Add a capacitor (e.g., 10 µF) across the VCC and GND pins to stabilize the power supply.
    • Ensure the object being measured has a flat, hard surface for better reflection.
  3. Sensor Not Detecting Close Objects:

    • The HC-SR04 has a minimum range of 2 cm. Objects closer than this may not be detected accurately.
  4. Echo Pin Stays HIGH Indefinitely:

    • This may occur if no object is detected within the sensor's range. Ensure there is an object within 400 cm.

FAQs

Q: Can the HC-SR04 measure distances through transparent materials like glass?
A: No, the HC-SR04 relies on ultrasonic waves, which do not pass through transparent materials like glass effectively.

Q: Can I use the HC-SR04 with a 3.3V microcontroller?
A: Yes, but you will need a logic level shifter or a resistor divider for the Echo pin to avoid damaging the microcontroller.

Q: What is the maximum range of the HC-SR04?
A: The maximum range is 400 cm (4 meters), but accuracy may decrease at longer distances.

Q: How can I improve measurement accuracy?
A: Use a stable power supply, avoid ultrasonic noise sources, and ensure proper alignment of the sensor.