Obstacle detection system using HC-SR04, I2C LCD display and ESP32 board

ESP32 22-02-24
355 0

Tutorial plan

1- Principle of obstacle detection system using HC-SR04, I2C LCD screen and ESP32 board

2- Necessary system components

3- Obstacle detection system wiring diagram

4- Programming the ESP32 board board with MicroPython

 

 

Principle of obstacle detection system using HC-SR04, I2C LCD screen and ESP32 board

An obstacle detection system is a technology designed to identify and alert users or autonomous systems about obstacles or hazards in their environment. These systems are commonly used in various applications, including robotics, autonomous vehicles, drones, industrial automation, and assistive technologies. The primary goal is to enhance safety and prevent collisions by providing real-time information about the presence of obstacles.

The obstacle detection system using HC-SR04, I2C LCD screen, LED, buzzer, and ESP32 board operates based on the principles of ultrasonic distance measurement and sensor integration. Here's a step-by-step explanation of how the system works:

1- Ultrasonic Distance Measurement (HC-SR04):

The HC-SR04 ultrasonic sensor emits ultrasonic waves using the transducer on the trigger pin.

The waves travel through the air and bounce off any obstacle in their path.

The transducer on the echo pin receives the reflected waves.

2- Calculation of Distance:

The ESP32 board measures the time it takes for the ultrasonic waves to travel to the obstacle and back.

Using the speed of sound in air (approximately 343 meters per second), the ESP32 board calculates the distance to the obstacle.

3- Obstacle Detection:

A conditional statement checks if the measured distance is less than a predefined threshold (e.g., 20 cm).

If the distance is less than the threshold, an obstacle is considered detected.

4- Display on I2C LCD Screen:

The I2C LCD screen serves as a user interface by displaying relevant information  obstacle detection status.

5- LED Indication:

An LED is used to provide a visual indication of obstacle detection.

The LED is turned on when an obstacle is detected and turned off otherwise.

6- Buzzer Alert:

A buzzer is employed to provide an audible alert when an obstacle is detected.

The buzzer is activated, producing a tone, when the system identifies an obstacle.

Necessary system components

ESP32 board:

ESP32 card

The ESP32 is a powerful microcontroller developed by Espressif Systems. It's renowned for its integrated Wi-Fi and Bluetooth capabilities, making it a popular choice for various IoT (Internet of Things) applications.

HC-SR04 ultrasonic Sensor

HC-SR04

The HC-SR04 is an ultrasonic distance measuring sensor module.

I2C LCD Display (usually 16x2)

This screen is used for displaying a alert message if the HC-SR04 sensor detects an obstacle.

LED 

LED

In an obstacle detection system, an LED (Light Emitting Diode) can be used as a visual indicator to provide feedback about the detection status. The LED can be programmed to turn on or off based on whether an obstacle is detected within a certain range.

Resistance (220 ohm)

Résistance

The resistance needed for an LED (Light Emitting Diode) in a circuit is determined by Ohm's Law, which states that the resistance (R) is equal to the voltage (V) divided by the current (I).

Jumper Wires:

Jumper wires

For making temporary connections and wiring between components.

Breadboard:

Test plate

A breadboard is a useful tool for creating temporary electronic circuits. It allows you to connect components without soldering.

Mounting the obstacle detection system controlled by ESP32 board

Mounting the obstacle detection system controlled by ESP32 boardMounting the obstacle detection system controlled by ESP32 board

Attaching the I2C LCD Display :

- connect the VCC pin of the display to 5V pin of the ESP32 board

- connect the GND pin of the display to GND pin of the ESP32 board

- connect the SDA pin of the display to GPIO21 pin of the ESP32 board

- connect the SCL pin of the display to GPIO22 pin of the ESP32 board

Attaching the HC-SR04 sensor :

- Connect the VCC(+) pin of the HC-SR04 ultrasonic sensor to the 3.3V pin on the ESP32 board.

- Connect the Trig pin of the HC-SR04 ultrasonic sensor to GPIO16 pin on the ESP32 board.

- Connect the Echo pin of the HC-SR04 ultrasonic sensor to GPIO 17 pin on the ESP32 board.

- Connect the GND(-) pin of the DHT22 sensor to any ground (GND) pin on the ESP32 board.

Attaching the buzzer :

- Connect the (+) terminal of buzzer to GPIO23  pin on the ESP32 board.

- Connect the (-) terminal of buzzer to GND pin on the ESP32 board.

Attaching the red LED :

- Connect the negative terminal (cathode) of each LED to the ground (GND) of the ESP32 board.

- Connect a resistor between the GPIO19 pin and the positive terminal (anode) of the LED

Programming the ESP32 board board with MicroPython

To program an obstacle detection system using HC-SR04, a buzzer, an LED, and an ESP32 with Micropython, you'll need to follow these steps.

1- Make sure you have Micropython installed on your ESP32 board.

2- Flash your ESP32 with MicroPython using this file esp32-20210902-v1.17.bin.

3- import this library : hc-sr04 for HC-SR04 sensor

4- import this two libraries : i2c_lcd and lcd_api for I2C LCD screen

5- Create a new Python script and write the following code :

Explanation of the program 

If the HC-SR04 ultrasonic sensor detects an obstacle, the ESP32 board turns on the LED, sounds the buzzer and displays an alert message on the I2C LCD display. Otherwise, the ESP32 board turns off the LED, stops the buzzer and clears the alert message.

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info