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

HC-SR04 Ultrasonic Sensor

Image of HC-SR04 Ultrasonic Sensor

HC-SR04 Ultrasonic Sensor Documentation

Introduction

The HC-SR04 Ultrasonic Sensor is a versatile and cost-effective sensor that measures distance by emitting ultrasonic waves and detecting the time it takes for the echoes to return. It is widely used in robotics, obstacle avoidance systems, and range detection applications due to its non-contact measurement capability.

Common Applications and Use Cases

  • Robotics for obstacle detection and navigation
  • Distance measurement for parking sensors
  • Level control in tanks or bins
  • Interactive installations and proximity-based triggers

Technical Specifications

Key Technical Details

  • Operating Voltage: 5V DC
  • Operating Current: 15 mA
  • Ultrasonic Frequency: 40 kHz
  • Max Range: 4m
  • Min Range: 2cm
  • Resolution: 3 mm
  • Measuring Angle: 15 degrees

Pin Configuration and Descriptions

Pin Number Pin Name Description
1 VCC Power supply (5V DC)
2 Trig Trigger input (TTL pulse)
3 Echo Echo output (TTL level signal)
4 GND Ground

Usage Instructions

How to Use the Component in a Circuit

  1. Connect the VCC pin to the 5V output on the Arduino UNO.
  2. Connect the GND pin to one of the GND pins on the Arduino UNO.
  3. Connect the Trig pin to a digital I/O pin on the Arduino UNO.
  4. Connect the Echo pin to another digital I/O pin on the Arduino UNO.

Important Considerations and Best Practices

  • Ensure that the sensor is mounted on a stable surface to avoid measurement errors.
  • Avoid using the sensor in environments with high dust, humidity, or temperature fluctuations.
  • Keep the sensor's path clear of obstacles for accurate measurement.
  • Use a pull-up resistor if the Echo pin signal is weak.

Example Code for Arduino UNO

#include <Arduino.h>

// Define the Trig and Echo pin:
#define TRIG_PIN 9
#define ECHO_PIN 10

void setup() {
  // Initialize serial communication:
  Serial.begin(9600);
  // Define the Trig pin as an output and the Echo pin as an input:
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
}

void loop() {
  // Clear the Trig pin condition:
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  // Set the Trig pin HIGH for 10 microseconds:
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  // Read the Echo pin; pulseIn returns the duration (length of the pulse) in microseconds:
  long duration = pulseIn(ECHO_PIN, HIGH);

  // Calculate the distance (in cm) based on the speed of sound (340 m/s):
  long distance = duration * 0.034 / 2;

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

  // Delay for a half-second before the next measurement:
  delay(500);
}

Troubleshooting and FAQs

Common Issues Users Might Face

  • Inaccurate Readings: Ensure that the sensor is not facing any obstacles within its range and that it is mounted securely.
  • No Readings: Check the wiring, especially the VCC and GND connections, and ensure that the pins are correctly defined in the code.
  • Intermittent Readings: This could be due to electrical noise or interference. Try adding a capacitor between VCC and GND near the sensor.

Solutions and Tips for Troubleshooting

  • If the sensor is not functioning, try replacing it with another one to determine if the issue is with the sensor itself.
  • Use serial print statements to debug and check if the sensor is getting triggered and if the Echo pin is receiving the signal.
  • Ensure that the Arduino UNO board is not overloaded with too many tasks, as this can affect the timing and performance of the sensor.

FAQs

Q: Can the HC-SR04 sensor detect objects with soft surfaces? A: The sensor may have difficulty detecting soft or angled surfaces because they can absorb or deflect ultrasonic waves.

Q: What is the maximum range of the HC-SR04 sensor? A: The maximum range is approximately 4 meters, but optimal performance is usually within 2 meters.

Q: Can I use the HC-SR04 sensor with a 3.3V system? A: The HC-SR04 is designed for 5V systems. Using it with 3.3V may result in insufficient operation or damage to the sensor. Use a level shifter or a compatible sensor for 3.3V systems.

Note: The HC-SR04 Ultrasonic Sensor is not manufactured by Arduino UNO. The Arduino UNO is a microcontroller board used to interface with and control various electronic components, including the HC-SR04. The manufacturer part ID "Uno" refers to the Arduino UNO board, not the sensor itself.

Example Projects

hc sr`
Image of hc sr`: A project utilizing HC-SR04 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.
Task 1
Image of Task 1: A project utilizing HC-SR04 Ultrasonic Sensor in a practical application
This circuit uses an Arduino UNO to interface with an HC-SR04 Ultrasonic Sensor for distance measurement. The Arduino provides power to the sensor and reads the echo signal on pin D7, while triggering the sensor via pin D8. The provided code is a basic template for further development.
hscr04
Image of hscr04: A project utilizing HC-SR04 Ultrasonic Sensor in a practical application
This circuit interfaces an HC-SR04 Ultrasonic Sensor with an STM32F103C8T6 microcontroller. The microcontroller powers the sensor and reads distance measurements by triggering the sensor and receiving the echo signal.
circuitcycle
Image of circuitcycle: A project utilizing HC-SR04 Ultrasonic Sensor 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.

Example Projects

Image of hc sr`: A project utilizing HC-SR04 Ultrasonic Sensor in a practical application
hc sr`
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.
Image of Task 1: A project utilizing HC-SR04 Ultrasonic Sensor in a practical application
Task 1
This circuit uses an Arduino UNO to interface with an HC-SR04 Ultrasonic Sensor for distance measurement. The Arduino provides power to the sensor and reads the echo signal on pin D7, while triggering the sensor via pin D8. The provided code is a basic template for further development.
Image of hscr04: A project utilizing HC-SR04 Ultrasonic Sensor in a practical application
hscr04
This circuit interfaces an HC-SR04 Ultrasonic Sensor with an STM32F103C8T6 microcontroller. The microcontroller powers the sensor and reads distance measurements by triggering the sensor and receiving the echo signal.
Image of circuitcycle: A project utilizing HC-SR04 Ultrasonic Sensor in a practical application
circuitcycle
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.