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

How to Use ultrasonic sensor: Examples, Pinouts, and Specs

Image of ultrasonic sensor
Cirkit Designer LogoDesign with ultrasonic sensor in Cirkit Designer

Introduction

An ultrasonic sensor is a device that uses ultrasonic waves to measure distance or detect objects. It emits a sound wave at a frequency higher than the audible range and measures the time it takes for the echo to return, allowing it to calculate the distance to the object.

Ultrasonic sensors are widely used in various applications, including:

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

Explore Projects Built with ultrasonic sensor

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 ultrasonic sensor 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 Radar System with Servo Motor
Image of ultrasonic radar: A project utilizing ultrasonic sensor 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 Bluetooth Interface and Visual Feedback
Image of BMO: A project utilizing ultrasonic sensor in a practical application
This circuit features an Arduino UNO microcontroller interfaced with an HC-SR04 ultrasonic sensor, a red LED with a series resistor, a buzzer, an I2C LCD 16x2 screen, and an HC-05 Bluetooth module. The ultrasonic sensor is likely used for distance measurement, with the Arduino controlling the LED and buzzer as indicators, displaying information on the LCD screen, and potentially communicating data wirelessly via the HC-05 Bluetooth module. The provided code skeleton suggests that the specific functionalities are yet to be implemented.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino-Controlled Robotic Vehicle with Ultrasonic and IR Sensors
Image of Copy of Circuit Diagram: A project utilizing ultrasonic sensor in a practical application
This circuit features an Arduino UNO microcontroller interfaced with an HC-SR04 Ultrasonic Sensor, two IR sensors, a servo motor, two DC motors, and an L298N motor driver. The Arduino controls the motors using the L298N driver, with the ability to move them forward or backward at variable speeds as defined in the embedded code. The ultrasonic sensor is used for distance measurement, the IR sensors likely for obstacle detection, and the servo for precise angular movement, all powered by 12V batteries.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with ultrasonic sensor

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 ultrasonic sensor 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 ultrasonic radar: A project utilizing ultrasonic sensor 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 BMO: A project utilizing ultrasonic sensor in a practical application
Arduino UNO-Based Ultrasonic Distance Measurement with Bluetooth Interface and Visual Feedback
This circuit features an Arduino UNO microcontroller interfaced with an HC-SR04 ultrasonic sensor, a red LED with a series resistor, a buzzer, an I2C LCD 16x2 screen, and an HC-05 Bluetooth module. The ultrasonic sensor is likely used for distance measurement, with the Arduino controlling the LED and buzzer as indicators, displaying information on the LCD screen, and potentially communicating data wirelessly via the HC-05 Bluetooth module. The provided code skeleton suggests that the specific functionalities are yet to be implemented.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Copy of Circuit Diagram: A project utilizing ultrasonic sensor in a practical application
Arduino-Controlled Robotic Vehicle with Ultrasonic and IR Sensors
This circuit features an Arduino UNO microcontroller interfaced with an HC-SR04 Ultrasonic Sensor, two IR sensors, a servo motor, two DC motors, and an L298N motor driver. The Arduino controls the motors using the L298N driver, with the ability to move them forward or backward at variable speeds as defined in the embedded code. The ultrasonic sensor is used for distance measurement, the IR sensors likely for obstacle detection, and the servo for precise angular movement, all powered by 12V batteries.
Cirkit Designer LogoOpen Project in Cirkit Designer

Technical Specifications

Below are the key technical details for a typical ultrasonic sensor, such as the HC-SR04:

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

The ultrasonic sensor typically has four pins, as described below:

Pin Name Description
1 VCC Power supply pin (5V DC)
2 Trig Trigger pin: Sends a 10 µs pulse to initiate measurement
3 Echo Echo pin: Outputs a pulse width proportional to distance
4 GND Ground connection

Usage Instructions

How to Use the Ultrasonic Sensor in a Circuit

  1. Power the Sensor: Connect the VCC pin to a 5V power source 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. 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} ] 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 this may interfere with readings.
  • Use a capacitor (e.g., 10 µF) across the VCC and GND pins to stabilize the power supply.
  • The sensor may not work reliably with soft or sound-absorbing materials, as they may not reflect ultrasonic waves effectively.

Example Code for Arduino UNO

Below is an example of how to use the HC-SR04 ultrasonic sensor with an Arduino UNO:

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

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

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

  // Calculate the distance in centimeters
  float distance = duration * 0.034 / 2; // Speed of sound is ~0.034 cm/µs

  // 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, GND, Trig, and Echo are connected properly.
  2. Unstable or Fluctuating 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 out of range or made of sound-absorbing material.
    • Solution: Ensure the object is within the sensor's range (2 cm to 400 cm) and is reflective.
  4. Echo Pin Always HIGH or LOW

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

FAQs

Q: Can the ultrasonic sensor measure distance through glass?
A: Ultrasonic waves may not pass through glass effectively, as they are often reflected or absorbed. For such applications, consider alternative sensors like infrared.

Q: What is the maximum angle of detection for the sensor?
A: The HC-SR04 has a detection angle of approximately 15 degrees. Ensure objects are within this cone for accurate measurements.

Q: Can I use the sensor with a 3.3V microcontroller?
A: While the sensor operates at 5V, you can use a level shifter to safely interface it with a 3.3V microcontroller.