Object Detection Using the HC-RS04 and Arduino

by fikunyin.adebola in Circuits > Arduino

157 Views, 2 Favorites, 0 Comments

Object Detection Using the HC-RS04 and Arduino

20240701_044516_093903.jpg
PXL_20240701_114755956.jpg

In this project, we will build an object detection system using the HC-SR04 ultrasonic sensor and an Arduino Uno. The system has a variety of practical uses, such as preventing theft, monitoring areas to detect pets or rodents, and much more.

Features:

  1. LCD Module: Displays messages as an object or intruder approaches.
  2. Buzzer: Provides an audible alert to notify the owner when an object is detected.

This tutorial will guide you through building this simple project in three easy steps.

Supplies

WhatsApp Image 2024-10-15 at 00.21.55.jpeg

Arduino Uno

HC-SR04 Ultrasonic Sensor

LCD Module

Passive Buzzer

Breadboard

Jumper Wires

Setting Up and Testing Ultrasonic Sensor

The HC-SR04 ultrasonic sensor emits ultrasonic waves and measures the time it takes for the waves to bounce back from an object, allowing you to calculate the distance.

Connections:

  1. VCC to 5V on the Arduino
  2. GND to GND
  3. TRIG to digital pin 11
  4. ECHO to digital pin 12

Testing:

After wiring, upload the code below to test the sensor:

This code will display the distance to an object in the serial monitor. You can refer to this Complete Guide to Ultrasonic Sensors for further details on the sensor.

Setting Up and Testing LCD Display

Screenshot 2024-10-15 013913.png

The LCD module will display messages when the ultrasonic sensor detects an object.

Connections:

Follow the connection instructions in the helloworld example.

Testing:

Arduino IDE comes with a built-in Liquid Crystal Library. To test the display:

  1. Go to File > Examples > LiquidCrystal > HelloWorld.
  2. Upload the code and confirm that the LCD displays the "Hello World" message.


Bringing Everything Together

PXL_20240701_124446820.jpg
PXL_20240701_124432810.MP.jpg

Now that we've tested both the ultrasonic sensor and the LCD, it's time to integrate everything.

Connect Components:

  1. The ultrasonic sensor will detect objects, and the LCD will display a message depending on the object's proximity.
  2. Add a passive buzzer to digital pin 4. When the distance is below a certain threshold, the buzzer will sound an alert.

Final Code:

Upload the arduino file below. You might have to change some connections based on the digital pins used. Here's a basic version of the final code: