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, SSD1306 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 SSD1306 screen:
The SSD1306 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.
SSD1306 screen
The SSD1306 is a popular display controller used in OLED (Organic Light-Emitting Diode) screens. It's commonly employed in various electronics projects to showcase information on small screens. The SSD1306 controller is compatible with different screen sizes and is often integrated with microcontrollers like Arduino UNO board to display text, graphics, and images.
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 SSD1306 screen :
- 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 library :ssd1306.py for SSD1306 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 38 39 |
import machine from machine import Pin, I2C from hcsr04 import HCSR04 import ssd1306 import time # Configure SSD1306 screen i2c = I2C(-1, scl=Pin(22), sda=Pin(21)) oled_width = 128 oled_height = 64 oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c) # Configure HC-SR04 pins sensor = HCSR04(trigger_pin=16,echo_pin=17,echo_timeout_us=1000000) # Configure red led pin redled_pin=Pin(19, Pin.OUT) # Configure buzzer pin 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') if (distance<4): # Check if obstacle is detected # Activate buzzer and LED redled_pin.value(1) buzzer_pin.value(1) # show alert message on SSD1306 display oled.text('Attention!!!', 0, 0) oled.text('Obstacle', 0, 20) oled.text('detected', 0, 40) oled.show() else: # Disable buzzer and LED redled_pin.value(0) buzzer_pin.value(0) #clear SSD1306 screen oled.fill(0) oled.show() 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 SSD1306. 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