Obstacle detection robot based on ESP32 and HC-SR04

ESP32 21-11-24
210 0

Tutorial plan

1- What is an obstacle detection robot ?

2- Operation of the obstacle detection robot controlled by ESP32

3- Components Overview

4- Wiring Configuration

5- Micropython Code for ESP32

 

 

What is an obstacle detection robot ?

An obstacle detection robot is a type of robotic system designed to navigate environments while identifying and avoiding obstacles in its path. It typically uses sensors to detect objects, measure distances, and determine the best course of action to prevent collisions. Such robots are widely used in various applications, from autonomous vehicles to cleaning robots and industrial automation.

Key Features of an Obstacle Detection Robot

1- Sensors for Detection:

Ultrasonic Sensors: Emit sound waves and measure the time taken for the echoes to return, helping to calculate distances.

Infrared (IR) Sensors: Use infrared light to detect nearby objects.

LiDAR (Light Detection and Ranging): Provides precise distance measurement and 3D mapping of the surroundings.

Cameras: Help in visual object recognition and detection.

Bump Sensors: Trigger when physical contact with an obstacle occurs.

2- Control System:

Usually powered by a microcontroller (e.g., Arduino, Raspberry Pi) or a dedicated processor.

The system processes sensor data to identify obstacles and make navigation decisions.

3- Locomotion:

Wheels, tracks, or legs are used for movement. The choice depends on the terrain and application.

Motors (e.g., DC or stepper motors) drive the robot.

4- Obstacle Avoidance:

Algorithms such as pathfinding or reactive navigation guide the robot around obstacles.

Advanced robots use AI and machine learning for dynamic route planning.

Applications

Home Automation: Robotic vacuum cleaners like Roomba use obstacle detection to navigate around furniture and walls.

Autonomous Vehicles: Cars equipped with obstacle detection systems prevent collisions with pedestrians, other vehicles, or objects.

Industrial Automation: Robots in warehouses detect shelves, machinery, and humans to safely transport goods.

Search and Rescue: Robots navigate through debris in disaster zones, detecting obstacles like rubble and narrow pathways.

Agriculture: Autonomous robots avoid crops and other obstructions while performing tasks like harvesting or spraying.

 

Operation of the obstacle detection robot controlled by ESP32

An obstacle detection robot with 2 wheels controlled by ESP32, HC-SR04 ultrasonic sensor, a servo motor, and L298D motor driver module operates by using the ultrasonic sensor mounted on a servo motor for dynamic obstacle detection. The servo motor rotates the ultrasonic sensor to scan the environment, while the L298D motor driver controls the robot's wheels for navigation.

1- Initialization:

The ESP32 initializes the HC-SR04 sensor, servo motor, and L298D motor driver.

The servo motor is set to its center position to start scanning.

2- Environment Scanning:

The servo motor rotates the HC-SR04 sensor to specific angles (e.g., 0°, 90°, and 180°) to measure distances at different directions.

The HC-SR04 sends distance data to the ESP32.

3- Obstacle Detection:

The ESP32 analyzes the distance data to determine the path:

Clear path ahead: The robot moves forward.

Obstacle detected ahead: The ESP32 compares the distances to the left and right.

If the left is clear, the robot turns left.

If the right is clear, the robot turns right.

If neither side is clear, the robot reverses or stops.

4- Motor Control:

Based on the decision, the ESP32 sends signals to the L298D motor driver to:

Move forward, backward, or stop.

Turn left or right by controlling the direction of the two motors.

5- Continuous Operation:

The robot continuously scans the environment, detects obstacles, and adjusts its movement.

Components Overview

ESP32:

ESP32 card

Microcontroller used to process data from the HC-SR04 sensor and control the L298D motor driver.

HC-SR04 Ultrasonic Sensor:

HC-SR04

Detects obstacles by measuring the time it takes for sound waves to bounce back from objects.

Sends the measured distance data to the ESP32.

Servo Motor:

Rotates the ultrasonic sensor to scan left, center, and right for obstacle detection.

L298D Motor Driver Module:

Interfaces between the ESP32 and the DC motors.

Controls the speed and direction of the motors based on commands from the ESP32.

DC Motors and Wheels:

Provide locomotion for the robot.

Power Supply:

Batteries power the ESP32, motor driver, and motors (e.g., 7.4V or 12V battery for motors).

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.

 

Wiring Configuration

1- Servomotor to ESP32 :

Signal Pin: GPIO 15 (Configurable in code).

VCC: External 5V power supply.

GND: Common ground with ESP32.

1- HC-SR04 Ultrasonic Sensor to ESP32:

Trigger Pin: GPIO 17 (Configurable in code).

Echo Pin: GPIO 16 (Configurable in code).

VCC: 5V or 3V3 from ESP32 or external power source.

GND: Ground of ESP32.

2- L298D Motor Driver to ESP32:

IN1 (Motor A Forward): GPIO 22.

IN2 (Motor A Backward): GPIO 21.

IN3 (Motor B Forward): GPIO 19.

IN4 (Motor B Backward): GPIO 18.

ENA : GPIO 23

ENB : GPIO 5

Enable Pins (EN1/EN2): Connected to 5V or PWM pins for speed control.

VCC (Motor Supply): Connect to battery.

GND: Common ground with ESP32.

3- L298D to Motors:

Motor A: Connect one DC motor to OUT1 and OUT2.

Motor B: Connect the other DC motor to OUT3 and OUT4

 

Micropython Code for ESP32

Here’s an example code for controlling the robot:

You need to import DCMotor.py library to control the two motor and hc-sr04.py library to control the HC-SR04 sensors .

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