Controlling a two-wheeled ESP32 robot by phone

ESP32 27-11-24
26 0

Tutorial plan

1- Operation of the two-wheeled ESP32 robot by Smartphone

2- Components Overview

3- Wiring Configuration

4- Micropython Code for ESP32

5- Develop  mobile application with MIT App Inventor to command the robot

 

 

Operation of the two-wheeled ESP32 robot by Smartphone

Controlling a two-wheeled ESP32 robot via a smartphone using Bluetooth, an L298N motor driver, and a custom app built in MIT App Inventor involves the following process:

System Overview

1- ESP32 Microcontroller:

Acts as the brain of the robot.

Receives Bluetooth commands from the smartphone app and processes them to control the motors.

2- L298N Motor Driver Module:

Drives the two DC motors of the robot based on signals from the ESP32.

Converts low-power control signals into higher power for the motors.

3- DC Motors and Wheels:

Provide forward, backward, and turning movements for the robot.

4- Smartphone App:

Sends movement commands via Bluetooth to the ESP32.

Built using MIT App Inventor for a graphical control interface.

 

Components Overview

ESP32:

ESP32 card

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

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- 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.

2- 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 is the micropython program which allows to control the car by the Smartphone.

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

2- import this libraries :

ble_uart_peripheral.py and ble_advertising.py for Bluetooth communication

DCMotor.py library to control the two motors.

 

Develop  mobile application with MIT App Inventor to command the robot

1. Creating the application with App Inventor:

Create a mobile app with App Inventor.

Use the available Bluetooth components to establish a connection with the ESP32.

- Add button Scanner to search ESP32 board.

- Add button Stop to stop the search.

- Add button Connect to connect to ESP32 board.

- Add button Disconnect to disconnect from ESP32 board.

- Create buttons for Forward (F), Backward (B), Left (L), and Right (R).

Here is the Designer part of the application with App Inventor :

2. Programming the application with App Inventor:

a- Use the available blocks in App Inventor to establish a Bluetooth connection with the ESP32.

- Starting with Android 12, Bluetooth permissions have been enhanced to improve security and user data protection. This is why we must declare the authorizations that your application needs in the AndroidManifest.xml file. For Bluetooth, you'll need to include ACCESS_FINE_LOCATION, BLUETOOTH_SCAN, and possibly BLUETOOTH_CONNECT permissions, depending on the features you're using.

b- Use these programming blocks to send commands when buttons are pressed.

Download project Download application

 

How It Works

1- Pair the ESP32:

Pair your smartphone with the ESP32 via Bluetooth (name: ESP32_Robot).

2- Control the Robot:

Open the MIT App Inventor app and connect to the ESP32.

Press buttons to send commands:

F: Move forward.

B: Move backward.

L: Turn left.

R: Turn right.

3- Robot Response:

The ESP32 receives the command, processes it, and activates the L298N to control motor movement.

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