Arduino

HC-SR04 Ultrasonic Sensor Arduino Application

HC-SR04 Arduino Example, Ultrasonic Sensor, Distance Measure, Object Detection, Electronic Projects

Overview

In the field of electronics, sensors are essential to allowing machines to communicate with their surroundings. The HC-SR04 ultrasonic sensor is one such sensor that has grown in popularity among Arduino hobbyists.

HC-SR04 Ultrasonic Sensor Module
HC-SR04 Ultrasonic Sensor Module

Knowing How to Use the HC-SR04 Ultrasonic Sensor

The HC-SR04 ultrasonic sensor is a non-contact distance measuring module that measures an object’s distance from it using ultrasonic waves. There are two primary parts to it: a transmitter and a receiver. Ultrasonic waves are emitted by the transmitter, and the waves that bounce back after colliding with an object are detected by the receiver. The sensor measures the exact distance by tracking the time it takes for waves to reach the target and back.

Important Attributes and Details

The HC-SR04 sensor is a desirable option for Arduino applications due to its many features and characteristics. Among its notable characteristics are:

1. Broad Measurement Range: The HC-SR04 sensor is appropriate for a variety of applications because it can precisely detect distances between 2 and 400 cm.

2. High accuracy: The HC-SR04 sensor measures distance with an accuracy of up to 3 mm, making it a dependable and accurate tool.

3. Simple to Use: Even individuals who are new to electronics may easily link the sensor with Arduino boards.

4. Low Power Consumption: The energy-efficient and low-power consuming HC-SR04 sensor is perfect for projects where power consumption is an issue.

HC-SR04 Applications with Arduino

The ultrasonic sensor HC-SR04 is used in a number of Arduino projects. Typical uses for them include:

1. Obstacle Avoidance: Arduino-based robots are able to identify and avoid obstacles in their route by utilizing the HC-SR04 sensor.

2. Distance Measurement: The sensor can measure distances precisely, which makes it useful for applications like liquid level detectors and parking assistance systems.

3. Object Detection: The HC-SR04 sensor is helpful in applications such as automatic door opening systems since it can determine if items are present or not.

4. Security Systems: The HC-SR04 sensor can be used in Arduino security system applications to detect motion or proximity and initiate the necessary actions.

Electrical Parameters of HC-SR04

Working VoltageDC 5V
Working Current15mA
Working Frequency40Hz
Max. Range4m
Min. Range2cm
Measuring Angle15 Degrees
Trigger Input Sıgnal10uS TTL Pulse
Echo Output SignalInput TTL lever signal and the range in proportion
Dimension45*20*15mm

Getting Started with HC-SR04 and Arduino

To begin using the HC-SR04 sensor with Arduino, you will need the following components:

1. Arduino board (such as Arduino Uno or Arduino Nano)

2. HC-SR04 ultrasonic sensor

3. Breadboard and jumper wires

4. Arduino IDE (Integrated Development Environment)

Wiring Diagram

HC-SR04 to Arduino Wiring Diagram
HC-SR04 to Arduino Wiring Diagram

HC-SR04 to Arduino Connection
HC-SR04 to Arduino Connection

Example Code

//adding libraries
#include "Ultrasonic.h"

//Define pins ultrasonic(trig,echo)
Ultrasonic ultrasonic(A0,A1);

//defining variable
int distance;

void setup() 
{
  Serial.begin(9600);
}

void loop()
{
  distance = ultrasonic.Ranging(CM); //Use 'CM' for centimeters or 'INC' for inches
  
  //Print distance to serial monitor
  Serial.print("Object found at: ");
  Serial.print(distance);
  Serial.println("cm");
   
  delay(1000); //delay for each 1 second
}

Program Outputs

HC-SR04 Output on Serial Monitor
HC-SR04 Output on Serial Monitor

Leave a Reply

Your email address will not be published. Required fields are marked *