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
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:
- LCD Module: Displays messages as an object or intruder approaches.
- 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
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:
- VCC to 5V on the Arduino
- GND to GND
- TRIG to digital pin 11
- 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.
Downloads
Setting Up and Testing LCD Display
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:
- Go to File > Examples > LiquidCrystal > HelloWorld.
- Upload the code and confirm that the LCD displays the "Hello World" message.
Bringing Everything Together
Now that we've tested both the ultrasonic sensor and the LCD, it's time to integrate everything.
Connect Components:
- The ultrasonic sensor will detect objects, and the LCD will display a message depending on the object's proximity.
- 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: