Making a Proximity Sensor With the HC-SR04 Ultrasonic Sensor

by romanmilla8 in Circuits > Arduino

361 Views, 0 Favorites, 0 Comments

Making a Proximity Sensor With the HC-SR04 Ultrasonic Sensor

Sensor-ultrasonik.jpg

The HC-SR04 is a non-contact sensor that uses ultrasonic proximity. The working principle of this sensor is similar to the echolocation system in catfish, where there is a transmitter that sends a beam of ultrasonic waves having velocity v, then the time it takes until the reflection of the object (t) is measured. The length of time is proportional to twice the distance between the sensor and the object (R), so that the distance between the sensor and the object can be determined in equation (2.19).

Based on the datasheet the HC-SR04 can measure distances in the range between 3 cm - 400 cm with an output pulse length proportional to the object distance. Its accuracy can reach 3mm.

This sensor only requires 2 I / O pins to communicate with the microcontroller, namely TRIGGER and ECHO. To activate it, the microcontroller sends a positive pulse through the TRIGGER pin of at least 10 us, then the sensor will send 8 signals with a frequency of 40kHz and detect whether a signal is returning to the sensor because it is reflected by an object. If there is a signal that returns to the sensor, it will be read by the receiver from the sensor. The time span from the transmitted to received signal is directly proportional to the distance from the object that reflects the signal.

For making a prototype to find out how to use the HC-SR04 ultrasonic sensor, using the Arduino IDE will be faster. The reader is assumed to have an Arduino Uno board. If not, it is recommended to buy it in advance at SHOP BEY by accessing the following purchase page

​Prepare Tools and Materials

HC-sr04.png

Komponen Elektronika or The electronic components used are :

1. Ultrasonic sensor HC-SR04

2. Arduino

3. Project Board

Create a Wiring Like the Image Above

mengukur-jarak-HC-SR04.jpg

Make the HC-SR04 ultrasonic sensor pin configuration as follows :

  • Pin VCC = 5 Volt DC Arduino
  • Pin GND = GND Arduino
  • Pin Echo = Digital 2 Arduino
  • Pin Trigger = Digital 4 Arduino

Upload the Code Above Below to Arduino

arduino-upload.jpg

#define trigPin 11

#define echoPin 12

#define led 11

#define led2 10

void setup()
{

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

}

void loop()

{
long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

Serial.print(distance);

Serial.println(" cm");

delay(500);

}

Done....

serial.png

Wish You Luck........