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

How to Use Sensor - UltrassonicoHC - SR04: Examples, Pinouts, and Specs

Image of Sensor - UltrassonicoHC - SR04
Cirkit Designer LogoDesign with Sensor - UltrassonicoHC - SR04 in Cirkit Designer

Introduction

The HC-SR04 is an ultrasonic distance sensor that uses sonar to measure the distance to an object. It emits ultrasonic waves and measures the time it takes for the echo to return, allowing for accurate distance measurements. This sensor is widely used in robotics, obstacle detection, and automation systems due to its reliability, affordability, and ease of use.

Explore Projects Built with Sensor - UltrassonicoHC - 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 Mega 2560 Bluetooth-Controlled Ultrasonic Distance Measurement
Image of circuitcycle: A project utilizing Sensor - UltrassonicoHC - 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 Based Ultrasonic Distance Measurement with HC-SR04 and Bluetooth Communication via HC-05
Image of hc sr`: A project utilizing Sensor - UltrassonicoHC - 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 and ESP8266 Nodemcu Controlled Environment Monitoring System with Solar Charging
Image of SOLARM: A project utilizing Sensor - UltrassonicoHC - SR04 in a practical application
This circuit is designed for environmental monitoring and response, featuring sensors for temperature, humidity, distance, and soil moisture, with actuation through a servomotor and audio feedback. It is powered by a solar-charged battery system, indicating outdoor or remote deployment with renewable energy utilization.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO-Based Ultrasonic Sensor and Relay-Controlled Audio System
Image of BT Speaker: A project utilizing Sensor - UltrassonicoHC - SR04 in a practical application
This circuit features an Arduino UNO microcontroller interfaced with two HC-SR04 ultrasonic sensors for distance measurement, a 4-channel relay module for controlling external devices, and an EZ-SFX amplifier connected to two loudspeakers for audio output. The system is powered by a Polymer Lithium Ion Battery and includes basic setup and loop code for the Arduino.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with Sensor - UltrassonicoHC - 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 circuitcycle: A project utilizing Sensor - UltrassonicoHC - 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 hc sr`: A project utilizing Sensor - UltrassonicoHC - 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 SOLARM: A project utilizing Sensor - UltrassonicoHC - SR04 in a practical application
Arduino and ESP8266 Nodemcu Controlled Environment Monitoring System with Solar Charging
This circuit is designed for environmental monitoring and response, featuring sensors for temperature, humidity, distance, and soil moisture, with actuation through a servomotor and audio feedback. It is powered by a solar-charged battery system, indicating outdoor or remote deployment with renewable energy utilization.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of BT Speaker: A project utilizing Sensor - UltrassonicoHC - SR04 in a practical application
Arduino UNO-Based Ultrasonic Sensor and Relay-Controlled Audio System
This circuit features an Arduino UNO microcontroller interfaced with two HC-SR04 ultrasonic sensors for distance measurement, a 4-channel relay module for controlling external devices, and an EZ-SFX amplifier connected to two loudspeakers for audio output. The system is powered by a Polymer Lithium Ion Battery and includes basic setup and loop code for the Arduino.
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 HC-SR04 sensor is designed for precise distance measurement and operates using ultrasonic sound waves. Below are its key technical details:

Parameter Value
Operating Voltage 5V DC
Operating Current 15 mA
Measuring Range 2 cm to 400 cm
Measuring Angle 15°
Ultrasonic Frequency 40 kHz
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 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 source and the GND pin to ground.
  2. Connect the Trigger Pin: Connect the Trig pin to a digital output pin of your microcontroller.
  3. Connect the Echo Pin: Connect the Echo pin to a digital input pin of your microcontroller.
  4. Send a Trigger Signal: Send a 10 µs HIGH pulse to the Trig pin to start the measurement.
  5. Read the Echo Signal: Measure the duration of the HIGH pulse on the Echo pin. The duration is proportional to the distance.

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 resistor divider or level shifter if connecting the Echo pin to a 3.3V microcontroller.
  • The sensor works best in environments with minimal obstructions and reflective surfaces.

Example Code for Arduino UNO

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

// Define pins for the HC-SR04 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 for the sensor
  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 centimeters
  long distance = duration * 0.034 / 2;

  // 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:

    • Ensure the sensor is powered with 5V and properly connected to the microcontroller.
    • Verify that the Trig and Echo pins are connected to the correct digital pins.
    • Check for loose or faulty wiring.
  2. Unstable or Fluctuating Measurements:

    • Ensure the sensor is not exposed to ultrasonic noise or vibrations.
    • Use a capacitor (e.g., 10 µF) across the VCC and GND pins to stabilize the power supply.
  3. Short Measuring Range:

    • Ensure there are no obstructions or reflective surfaces too close to the sensor.
    • Verify that the sensor is mounted at the correct angle.

FAQs

Q: Can the HC-SR04 measure distances below 2 cm?
A: No, the minimum measuring range of the HC-SR04 is 2 cm. Objects closer than this may not be detected accurately.

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

Q: What is the maximum distance the HC-SR04 can measure?
A: The maximum range is 400 cm, but accuracy may decrease at longer distances.

Q: How can I improve measurement accuracy?
A: Use the sensor in a stable environment, avoid ultrasonic interference, and ensure proper alignment with the target object.