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

How to Use Ultrasonic: Examples, Pinouts, and Specs

Image of Ultrasonic
Cirkit Designer LogoDesign with Ultrasonic in Cirkit Designer

Introduction

The HCSR-04 Ultrasonic Sensor, manufactured by Sensor, is a versatile and widely used electronic component designed for distance measurement and object detection. It operates by emitting ultrasonic sound waves and measuring the time it takes for the echo to return after bouncing off an object. This time-of-flight measurement allows for accurate distance calculations.

Explore Projects Built with Ultrasonic

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 Radar System with Servo Motor
Image of ultrasonic radar: A project utilizing Ultrasonic in a practical application
This circuit is designed to function as an ultrasonic radar system, utilizing an Arduino UNO microcontroller, an HC-SR04 ultrasonic sensor, and an SG90 servo motor. The Arduino controls the servo to sweep the ultrasonic sensor through a range of angles, while the sensor measures the distance to any objects in its path. The system outputs the angle and distance measurements to the serial monitor and provides an indication when an obstacle is detected within 20 cm.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO Based Ultrasonic Distance Measurement with HC-SR04 and Bluetooth Communication via HC-05
Image of hc sr`: A project utilizing Ultrasonic 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 UNO Based Ultrasonic Distance Measurement with Audio Feedback
Image of inspection project: A project utilizing Ultrasonic in a practical application
This circuit features an Arduino UNO microcontroller interfaced with an HC-SR04 Ultrasonic Sensor and a DFPlayer MINI MP3 module. The Arduino controls the ultrasonic sensor to measure distances and uses the DFPlayer MINI to play audio through a connected loudspeaker based on the sensor readings. The circuit is likely designed for an interactive project where audio feedback is provided when objects are detected at certain distances.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino Mega 2560 Controlled Robot with Ultrasonic Obstacle Avoidance and Bluetooth Connectivity
Image of solar grass cutter : A project utilizing Ultrasonic in a practical application
This circuit features an Arduino Mega 2560 microcontroller interfaced with an HC-SR04 ultrasonic sensor for distance measurement, a Bluetooth HC-06 module for wireless communication, and a Servomotor SG90 for directional control. It controls two DC worm gear motors via a 5V 8-channel relay module, which is powered by a 12V battery. The system is designed for remote-controlled and autonomous obstacle avoidance, with the Arduino programmed to respond to Bluetooth commands and to automatically navigate around obstacles detected by the ultrasonic sensor.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with Ultrasonic

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 ultrasonic radar: A project utilizing Ultrasonic in a practical application
Arduino UNO Based Ultrasonic Radar System with Servo Motor
This circuit is designed to function as an ultrasonic radar system, utilizing an Arduino UNO microcontroller, an HC-SR04 ultrasonic sensor, and an SG90 servo motor. The Arduino controls the servo to sweep the ultrasonic sensor through a range of angles, while the sensor measures the distance to any objects in its path. The system outputs the angle and distance measurements to the serial monitor and provides an indication when an obstacle is detected within 20 cm.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of hc sr`: A project utilizing Ultrasonic 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 inspection project: A project utilizing Ultrasonic in a practical application
Arduino UNO Based Ultrasonic Distance Measurement with Audio Feedback
This circuit features an Arduino UNO microcontroller interfaced with an HC-SR04 Ultrasonic Sensor and a DFPlayer MINI MP3 module. The Arduino controls the ultrasonic sensor to measure distances and uses the DFPlayer MINI to play audio through a connected loudspeaker based on the sensor readings. The circuit is likely designed for an interactive project where audio feedback is provided when objects are detected at certain distances.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of solar grass cutter : A project utilizing Ultrasonic in a practical application
Arduino Mega 2560 Controlled Robot with Ultrasonic Obstacle Avoidance and Bluetooth Connectivity
This circuit features an Arduino Mega 2560 microcontroller interfaced with an HC-SR04 ultrasonic sensor for distance measurement, a Bluetooth HC-06 module for wireless communication, and a Servomotor SG90 for directional control. It controls two DC worm gear motors via a 5V 8-channel relay module, which is powered by a 12V battery. The system is designed for remote-controlled and autonomous obstacle avoidance, with the Arduino programmed to respond to Bluetooth commands and to automatically navigate around obstacles detected by the ultrasonic sensor.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications and Use Cases

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

Technical Specifications

The HCSR-04 Ultrasonic Sensor is designed for ease of use and reliable performance. Below are its key technical details:

Parameter Value
Operating Voltage 5V DC
Operating Current 15 mA
Operating Frequency 40 kHz
Measuring Range 2 cm to 400 cm
Accuracy ±3 mm
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 HCSR-04 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 ultrasonic transmission.
3 Echo Echo pin. Outputs a pulse width proportional to the distance of the detected object.
4 GND Ground pin. Connect to the ground of the power supply.

Usage Instructions

How to Use the HCSR-04 in a Circuit

  1. Power the Sensor: Connect the VCC pin to a 5V DC power source and the GND pin to ground.
  2. Trigger the Sensor: Send a 10 µs HIGH pulse to the Trig pin to initiate ultrasonic transmission.
  3. Read the Echo: Measure the duration of the HIGH pulse on the Echo pin. This 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} ] The factor 58 accounts for the speed of sound in air (343 m/s).

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 this 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 detection range of 2 cm. Objects closer than this may not be detected accurately.

Example: Connecting to an Arduino UNO

Below is an example of how to connect and use the HCSR-04 with an Arduino UNO:

Circuit Connections

HCSR-04 Pin Arduino UNO Pin
VCC 5V
Trig Digital Pin 9
Echo Digital Pin 10
GND GND

Arduino Code

// Define pins for the HCSR-04 Ultrasonic Sensor
const int trigPin = 9;  // Trigger pin connected to Arduino pin 9
const int echoPin = 10; // Echo pin connected to Arduino pin 10

void setup() {
  // Initialize serial communication for debugging
  Serial.begin(9600);
  
  // Set pin modes
  pinMode(trigPin, OUTPUT); // Trig pin as output
  pinMode(echoPin, INPUT);  // Echo pin as 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 cm
  float distance = duration / 58.0;

  // Print the distance to the Serial Monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  // Wait before the next measurement
  delay(500);
}

Troubleshooting and FAQs

Common Issues and Solutions

  1. No Output or Incorrect Readings

    • Cause: Loose or incorrect wiring.
    • Solution: Double-check all connections, ensuring VCC and GND are properly connected.
  2. Unstable Distance Measurements

    • Cause: Electrical noise or unstable power supply.
    • Solution: Add a decoupling capacitor (e.g., 10 µF) across the VCC and GND pins.
  3. Sensor Not Detecting Objects

    • Cause: Object is outside the sensor's range or too small to reflect sound waves.
    • Solution: Ensure the object is within the 2 cm to 400 cm range and has a sufficient surface area.
  4. Echo Pin Always HIGH or LOW

    • Cause: Faulty sensor or incorrect trigger signal.
    • Solution: Verify the trigger signal is a 10 µs HIGH pulse. Replace the sensor if necessary.

FAQs

Q: Can the HCSR-04 detect transparent objects?
A: The sensor may struggle to detect transparent objects like glass, as they may not reflect ultrasonic waves effectively.

Q: What is the maximum angle of detection?
A: The HCSR-04 has a detection angle of approximately 15 degrees.

Q: Can I use the HCSR-04 with a 3.3V microcontroller?
A: The HCSR-04 requires a 5V power supply. Use a level shifter for compatibility with 3.3V logic.

Q: How do I improve accuracy?
A: Use multiple measurements and average the results to reduce noise and improve accuracy.