Bluetooth control of DC Motor using ESP32 and Smartphone

ESP32 02-07-26
14 0

Tutorial plan

1- Objective of the project

2- Required Components

3- Circuit Connections of system

4- MicroPython program for ESP32 board

5- The mobile app for controlling the motor

 

Objective of the project

The objective of this project is to design and implement a wireless DC motor control system using an ESP32, a Bluetooth connection, an L298N motor driver module, and a smartphone. The system enables the user to remotely start and stop the motor, change its direction of rotation, and adjust its speed through a mobile application.

Operation

The ESP32 establishes a Bluetooth connection with the smartphone. Once the connection is established, the user sends control commands from the mobile application. The ESP32 receives these commands and processes them to generate the appropriate control signals.

These signals are transmitted to the L298N motor driver module, which provides the required power to the DC motor while controlling its operating state. Depending on the received command, the L298N starts or stops the motor, changes its direction of rotation, or adjusts its speed using Pulse Width Modulation (PWM). An external battery pack supplies the power required by the motor, while the ESP32 manages the control logic.

This wireless system provides a simple and efficient way to control a DC motor remotely using a smartphone, making it suitable for robotics, automation, and educational applications.

 

Required Components

1. ESP32 board

The ESP32 is a powerful microcontroller with built-in Bluetooth and Wi-Fi capabilities. It receives the commands sent from the smartphone via Bluetooth, processes them, and generates the control signals required to drive the DC motor.

2. L298N Motor Driver Module :

The L298N motor driver module acts as an interface between the ESP32 and the DC motor. It receives the control signals from the ESP32 and supplies the power required by the motor. It controls the motor's operating state, including start, stop, direction of rotation, and speed.

3. DC Motor (5 V)

The 5 V DC motor converts electrical energy into mechanical rotational motion. Its speed and direction are controlled by the L298N motor driver according to the commands received from the ESP32.

4. Jumper Wires

Jumper wires

Jumper wires are used to connect the ESP32, the L298N module, the power supply, and the DC motor, ensuring reliable transmission of power and control signals.

Breadboard (Optional)

plaque d'essai

A breadboard provides a convenient platform for assembling and testing the electronic circuit without soldering. It allows components and jumper wires to be connected easily during prototyping.

5. External Power Supply (2 × 3.7 V Batteries)

The two 3.7 V rechargeable batteries provide the external power required by the L298N motor driver and the DC motor. This independent power source ensures stable motor operation while preventing excessive current draw from the ESP32.

 

Circuit Connections of system

 

1- L298N to Motor Connections:

OUT1 and OUT2: Connect to the two terminals of Motor A.

2- Power Connections:

12V: Connects to the motor power supply (9v battery).

GND: Common ground connection for the motor, ESP32, and power supply.

ESP32 to L298N Connections:

ENA: Connects to a PWM-capable GPIO on the ESP32 (e.g., GPIO 23).

IN1 and IN2: Connect to GPIO pins on the ESP32 (e.g., GPIO 21 and GPIO 22).

 

MicroPython Program for the ESP32 Board

This MicroPython program enables an ESP32 to control the speed and direction of a DC motor through a Bluetooth Low Energy (BLE) connection with a smartphone. The ESP32 receives wireless commands from a mobile application and uses an L298N motor driver module to operate the motor accordingly.

Import this three libraries : ble_uart_peripheral.pyble_advertising.py and DCMotor.

 

The mobile app for controlling the motor

Download application

 

This mobile application is a simple Bluetooth control interface for a DC motor. It is designed to communicate with an ESP32 module and allows the user to control the motor remotely in real time.

At the top of the interface, there are four main control buttons:

- Scanner: used to search for available Bluetooth devices.

- Connect: establishes a Bluetooth connection with the ESP32.

- Disconnect: terminates the Bluetooth connection.

- Stop: immediately stops the motor for safety and control.

The main section of the application is titled “Control Motor” and provides the user interface for motor operation. It includes a visual representation of the motor to make the application more intuitive.

Below the image, the user can select the direction of rotation using two options:

- Clockwise (forward rotation)

- Anticlockwise (reverse rotation)

Only one direction is used at a time depending on the selected control mode.

At the bottom, a speed control slider allows the user to adjust the motor speed. The current speed value is displayed (e.g., “Speed: 0”), and the slider sends the corresponding value to the ESP32 via Bluetooth.

Overall, this application provides an easy-to-use interface for wireless control of a DC motor, combining device connection, direction selection, and speed adjustment in a single screen.

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

Pictures of the articles

Robotic site created by Mohamed Ali Haj Salah - Teacher info