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.
ESP32 board:
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
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
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)
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:
For making temporary connections and wiring between components.
Breadboard:
A breadboard is a useful tool for creating temporary electronic circuits. It allows you to connect components without soldering.
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
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 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import machine from machine import Pin, SoftI2C from lcd_api import LcdApi from i2c_lcd import I2cLcd from hcsr04 import HCSR04 import time # Configure I2C for LCD screen I2C_ADDR = 0x27 totalRows = 2 totalColumns = 16 i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000) #initializing the I2C method for ESP32 lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColumns) # Configure HC-SR04 pins sensor = HCSR04(trigger_pin=16,echo_pin=17,echo_timeout_us=1000000) # Configure buzzer and led pins redled_pin=Pin(19, Pin.OUT) buzzer_pin=Pin(23, Pin.OUT) while True: #calculate distance between the HC-SR04 sensor and an obstacle distance = sensor.distance_cm() print('distance= ',distance,' cm') # Check if obstacle is detected if (distance<4): # Activate buzzer and LED redled_pin.value(1) buzzer_pin.value(1) # show alert message on LCD I2C display lcd.putstr("attention!!") lcd.move_to(0,1) lcd.putstr("obstacle detecte") else: # Disable buzzer and LED redled_pin.value(0) buzzer_pin.value(0) lcd.clear() time.sleep_ms(100) |
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.
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.
Zaouiet Kontech-Jemmel-Monastir-Tunisia
+216 92 886 231
medaliprof@gmail.com
Robotic site created by MedAli-Teacher info