Beijing Ultrasonic

  • Products
  • Contact Us
  • No products in cart.
  • EnglishEnglish
    • Español Español
    • Français Français
    • Deutsch Deutsch
    • Italiano Italiano
    • Português Português
    • Українська Українська
    • Русский Русский
    • Türkçe Türkçe
    • Polski Polski
    • Nederlands Nederlands
    • Čeština Čeština
    • Svenska Svenska
    • עברית עברית
    • العربية العربية
    • فارسی فارسی
    • 简体中文 简体中文
    • 日本語 日本語
    • 한국어 한국어
    • हिन्दी हिन्दी
    • Melayu Melayu
    • Indonesia Indonesia
    • Tiếng Việt Tiếng Việt
  • Home
  • Blog
  • Ultrasonic Technology
  • How to connect ultrasonic sensor

How to connect ultrasonic sensor

by Jessie Wong / Friday, 21 April 2023 / Published in Ultrasonic Technology

Ultrasonic sensors are versatile and widely used in various applications, ranging from object detection and distance measurement to industrial automation and robotics. Their ability to emit ultrasonic waves and measure the time it takes for the reflected waves to return makes them ideal for non-contact sensing tasks. This article explains how to connect an ultrasonic sensor to a microcontroller or device for functional use. We will take you through the steps needed to ensure the proper wiring and configuration of an ultrasonic sensor, prioritizing reliability and accuracy.

1. Understanding the Ultrasonic Sensor

An ultrasonic sensor works by emitting high-frequency sound waves (ultrasound) and then measuring the time it takes for the reflected sound wave to return. The most commonly used ultrasonic sensor is the HC-SR04, but advanced sensors from brands like Beijing Ultrasonic are also widely used due to their superior precision and durability.

The basic pins of an ultrasonic sensor typically include:

Pin Name Function
VCC Power input, usually 5V or 3.3V
GND Ground connection
Trigger (TRIG) Input signal to initiate the ultrasonic pulse
Echo Output signal that represents the time taken for the echo to return

2. Tools and Components Required

To connect and use an ultrasonic sensor, you will need the following:

  • An ultrasonic sensor (e.g., HC-SR04 or a device from Beijing Ultrasonic)
  • A microcontroller (e.g., Arduino, Raspberry Pi, or any other compatible board)
  • Jumper wires for connections
  • A breadboard for prototyping (optional)
  • Power source (compatible with the microcontroller and sensor)
  • Resistors (if needed for voltage level matching)
  • A system for reading data (e.g., a laptop with Arduino IDE or Python installed)

3. Wiring the Ultrasonic Sensor

To connect the ultrasonic sensor to your microcontroller, follow these steps carefully:

  1. Power Connections

    • Connect the VCC pin of the sensor to the 5V or 3.3V output of the microcontroller (check the sensor’s specifications for proper voltage levels).
    • Connect the GND pin of the sensor to the GND pin on the microcontroller.
  2. Trigger and Echo Pins

    • Connect the Trigger (TRIG) pin of the sensor to a digital I/O pin on the microcontroller (e.g., Arduino pin 9).
    • Connect the Echo pin to another digital I/O pin on the microcontroller (e.g., Arduino pin 10).
  3. Voltage Considerations for Echo Signal
    Some sensors output a 5V signal on the Echo pin, which may be incompatible with microcontrollers like the Raspberry Pi that operate on 3.3V. In such cases, a voltage divider circuit using resistors can be used. Here’s an example of a voltage divider:

    Resistor Value Connection
    R1 (e.g., 1 kΩ) Connect between the Echo pin and microcontroller input pin
    R2 (e.g., 2 kΩ) Connect between the microcontroller input pin and GND

    This will step down the voltage safely for a 3.3V microcontroller.

4. Configuring the Software

Once the wiring is complete, you’ll need to program the microcontroller to read data from the ultrasonic sensor. Let’s look at how to configure the sensor using an Arduino as an example.

  1. Install Arduino IDE
    Ensure that the Arduino IDE is installed on your system. Connect your Arduino to the computer via USB.

  2. Write the Code
    Use the following sample code to measure the distance using an ultrasonic sensor. This code assumes the Trigger pin is connected to pin 9 and the Echo pin is connected to pin 10.

    const int trigPin = 9;
    const int echoPin = 10;
    long duration;
    int distance;
    
    void setup() {
     pinMode(trigPin, OUTPUT);
     pinMode(echoPin, INPUT);
     Serial.begin(9600);
    }
    
    void loop() {
     // Clear the trigger pin
     digitalWrite(trigPin, LOW);
     delayMicroseconds(2);
    
     // Set the trigger pin HIGH for 10 microseconds
     digitalWrite(trigPin, HIGH);
     delayMicroseconds(10);
     digitalWrite(trigPin, LOW);
    
     // Read the echo pin, and calculate the distance
     duration = pulseIn(echoPin, HIGH);
     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");
     delay(500);
    }
  3. Upload the Code
    Upload the code to the Arduino board and open the Serial Monitor to observe the distance measurement.

5. Testing and Calibration

Once the sensor is connected and programmed, it’s essential to test and calibrate its performance:

  • Place objects at known distances from the sensor and check the readings.
  • Adjust for environmental factors like temperature and humidity, which may slightly affect the speed of sound and thus the accuracy of measurements.
  • If using a sensor from Beijing Ultrasonic, refer to the manufacturer’s datasheet for any specific calibration instructions.

6. Troubleshooting Common Issues

If the ultrasonic sensor does not work as expected, consider the following:

  • Incorrect Wiring: Double-check all connections to ensure they match the sensor’s pinout and microcontroller configuration.
  • Voltage Mismatch: Ensure proper voltage levels, especially on the Echo pin.
  • Faulty Sensor: Test the system with a replacement sensor to rule out hardware issues.
  • Code Issues: Verify that the correct pins and logic are used in the code.
  • Obstructions: Ensure the path between the sensor and the target object is clear of obstructions.

Connecting an ultrasonic sensor to a microcontroller is a straightforward process that involves understanding its pinout, making proper electrical connections, and configuring the software appropriately. With reliable sensors like those from Beijing Ultrasonic, you can achieve accurate distance measurements for a wide range of applications. By following the steps outlined above, you’ll be able to set up and use an ultrasonic sensor effectively in your projects. Proper testing and calibration will ensure optimal performance and accuracy.

What you can read next

3L Mechanical Ultrasonic Cleaner Time Temperature-04
What Do I Need to Be Able to Reuse the Cleaning Bath and Oil
How to use total comfort ultrasonic humidifier
Humidifier
DIY electric essential oil diffuser

Product categories

  • Piezoceramics
    • Piezoceramic Ball/Hemisphere
    • Piezoceramic Cylinder
    • Piezoceramic Discs
    • Piezoceramic Rings
    • Piezoceramic Square/Rectangular
    • Piezoceramic Tube
  • Ultrasonic Cleaner
    • 120kHz Digital Ultrasonic Cleaner
    • 40kHz Digital Ultrasonic Cleaner
    • 80kHz Digital Ultrasonic Cleaner
    • Dual Frequency Digital Ultrasonic Cleaner
    • Immersible Ultrasonic Transducer
    • Industrial Ultrasonic Cleaner
    • Mechanical Ultrasonic Cleaner
    • Power Adjustable Digital Ultrasonic Cleaner
  • Ultrasonic Generator
    • [100-120V] Ultrasonic Transducer Driver Circuit & Transducer Bundles
    • [100-120V/200-240V] Ultrasonic Transducer Driver Circuit & Transducer Bundles
    • [200-240V] Ultrasonic Transducer Driver Circuit & Transducer Bundles
    • Digital Ultrasonic Generator
    • Digital Ultrasonic Transducer Driver Circuit & Transducer Bundles
    • Ultrasonic Transducer Driver Circuit
  • Ultrasonic Humidifier
  • Ultrasonic Meter
  • Ultrasonic Processor
    • Ultrasonic Biodiesel Reactor
    • Ultrasonic Homogenizer
  • Ultrasonic Transducer
  • Ultrasonic Welder

Recent Posts

  • 2L Mechanical Ultrasonic Cleaner Time Temperature-05

    A Comprehensive Guide to Wholesale Ultrasonic Cleaners

    Ultrasonic cleaning technology has revolutioniz...
  • The Benefits of Combining Disruption and Homogenization in a Single Instrument

    Combining disruption and homogenization capabil...
  • Ensuring Cleanroom Compatibility: Ultrasonic Welding in Electronics Manufacturing

    The electronics industry demands manufacturing ...
  • Ultrasonic Welding: A Boon for Innovation in Consumer Goods

    Ultrasonic welding has emerged as a pivotal tec...
  • 5000ML Fog Water Fountain Ultrasonic Cool Mist Humidifier (2)

    The Science of Moisture: How Ultrasonic Humidifiers Add Humidity to Your Air

    Ultrasonic humidifiers have become a popular ch...
  • Beyond Heat and Glue: The Science Behind Ultrasonic Bonds

    The realm of manufacturing and assembly is cons...
  • Ultrasonic Sensors

    From Bumpers to Brakes: Piezoceramic Sensors in Automotive Applications

    Piezoceramic sensors have become indispensable ...
  • From Tough Tissues to Delicate Cells: The Power of Ultrasonic Homogenization for Diverse Samples

    Ultrasonic homogenization, a technique employin...
  • Ultrasonic Cell Disruptor Homogenizer Transducer (4)

    Streamlining Workflows in Microbiology: Ultrasonic Homogenization for Faster Sample Prep

    In the fast-paced world of microbiology, effici...
  • The Future of Sound: How Ultrasonic Generators are Shaping Diverse Industries

    The world of sound extends far beyond what the ...

Customer Care

  • My Account
  • About Us
  • Return Policy
  • Privacy Policy
  • Terms & Conditions
  • Resource Center
  • Blog & News
  • China Public Holiday
  • Sitemap

Technical Info

  • Ultrasonic Cleaner Overview
  • Ultrasonic Cleaner FAQs
  • Ultrasonic Generator Overview
  • Ultrasonic Generator FAQs
  • Ultrasonic Transducer Overview
  • Ultrasonic Transducer FAQs
  • Piezoceramics Overview
  • Piezoceramic FAQs

Product Catalog

Beijing-Ultrasonic-Product-Catalog

Secure Payment

Buy now with PayPal
  • GET SOCIAL

© 2011 - 2026 Beijing Ultrasonic. All Rights Reserved.

TOP