ESP32-Controlled Bluetooth Soccer Robot with Dual BTS7960 Motor Drivers
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary of the Circuit
This circuit is designed to control a pair of MRB Planetary gearbox motors using an ESP32 microcontroller and BTS7960 motor drivers. The ESP32 is also equipped with Bluetooth capabilities, allowing for wireless control signals to be received and processed to drive the motors in various directions and speeds. A Lipo Battery provides the power source, which is managed by an LM2596 voltage regulator to ensure stable operation of the ESP32 and motor drivers. A Rocker Switch (SPST) is included to control the power flow to the motor drivers.
Component List
Rocker Switch (SPST)
- Description: A single-pole single-throw (SPST) rocker switch used to control the power flow to the motor drivers.
- Pins: 1, 2
Lipo Battery
- Description: A rechargeable battery that provides power to the circuit.
- Pins: VCC, GND
ESP32
- Description: A microcontroller with Bluetooth capability for wireless control of the motors.
- Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, VIN, 3V3, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, BOOT
MRB Planetary Gearbox Motor
- Description: A motor with a gearbox for increased torque.
- Pins: +, -
BTS7960 Motor Driver
- Description: A high-power motor driver used to control the speed and direction of the motors.
- Pins: Pin 1 to Pin 12
LM2596
- Description: A voltage regulator to provide stable power to the ESP32 and motor drivers.
- Pins: IN, OUT
Wiring Details
Rocker Switch (SPST)
- Pin 1: Connected to the LM2596 IN pin and BTS7960 Motor Driver Pin 11.
- Pin 2: Connected to the Lipo Battery VCC pin.
Lipo Battery
- VCC: Connected to the Rocker Switch (SPST) Pin 2.
- GND: Connected to the BTS7960 Motor Driver Pin 12.
ESP32
- GND: Connected to the LM2596 OUT pin and BTS7960 Motor Driver Pin 1.
- VIN: Connected to the LM2596 OUT pin.
- 3V3: Connected to the BTS7960 Motor Driver Pins 3, 5, 7.
- D19: Connected to the BTS7960 Motor Driver Pin 8.
- D21: Connected to the BTS7960 Motor Driver Pin 4.
- D22: Connected to the BTS7960 Motor Driver Pin 8.
- D23: Connected to the BTS7960 Motor Driver Pin 4.
MRB Planetary Gearbox Motors
- Motor 1 (+): Connected to the BTS7960 Motor Driver Pin 9.
- Motor 1 (-): Connected to the BTS7960 Motor Driver Pin 10.
- Motor 2 (+): Connected to the BTS7960 Motor Driver Pin 9.
- Motor 2 (-): Connected to the BTS7960 Motor Driver Pin 10.
- Motor 3 (+): Connected to the BTS7960 Motor Driver Pin 9.
- Motor 3 (-): Connected to the BTS7960 Motor Driver Pin 10.
- Motor 4 (+): Connected to the BTS7960 Motor Driver Pin 9.
- Motor 4 (-): Connected to the BTS7960 Motor Driver Pin 10.
BTS7960 Motor Driver
- Pin 1: Connected to the ESP32 GND pin.
- Pin 3, 5, 7: Connected to the ESP32 3V3 pin.
- Pin 4: Connected to the ESP32 D21 and D23 pins.
- Pin 8: Connected to the ESP32 D19 and D22 pins.
- Pin 9: Connected to the MRB Planetary Gearbox Motors + pins.
- Pin 10: Connected to the MRB Planetary Gearbox Motors - pins.
- Pin 11: Connected to the Rocker Switch (SPST) Pin 1 and LM2596 IN pin.
- Pin 12: Connected to the Lipo Battery GND pin and LM2596 IN pin.
LM2596
- IN: Connected to the Rocker Switch (SPST) Pin 1, BTS7960 Motor Driver Pin 11, and Lipo Battery GND pin.
- OUT: Connected to the ESP32 GND and VIN pins.
Documented Code
The following code is written for the ESP32 microcontroller to control the MRB Planetary gearbox motors via Bluetooth commands. The code sets up the Bluetooth communication, initializes the motor control pins, and defines the PWM channels for motor speed control. It then enters a loop where it reads Bluetooth signals and sets the motor speeds and directions accordingly.
#include "BluetoothSerial.h"
#include <Arduino.h>
BluetoothSerial serialBT;
// Bluetooth signal Store in this variable
char btSignal;
// initial Speed of the Bot
int Speed = 100;
/* FOR RIGHT MOTOR */
int R1PWM = 19;
int R2PWM = 21;
/* FOR LEFT MOTOR */
int L1PWM = 23;
int L2PWM = 22;
// declare channel for pwm Output
#define R1 0
#define R2 1
#define L1 2
#define L2 3
void setup() {
Serial.begin(115200);
// Bluetooth Name
serialBT.begin("Joy's Soccer Bot Prime");
// output pin declare
pinMode(R1PWM, OUTPUT);
pinMode(R2PWM, OUTPUT);
pinMode(L1PWM, OUTPUT);
pinMode(L2PWM, OUTPUT);
// Setup PWM channels
ledcSetup(R1, 5000, 8); // Channel 0 for Motor A, 5 kHz frequency, 8-bit resolution
ledcAttachPin(R1PWM, R1);
ledcSetup(R2, 5000, 8); // Channel 1 for Motor B, 5 kHz frequency, 8-bit resolution
ledcAttachPin(R2PWM, R2);
ledcSetup(L1, 5000, 8); // Channel 0 for Motor A, 5 kHz frequency, 8-bit resolution
ledcAttachPin(L1PWM, L1);
ledcSetup(L2, 5000, 8); // Channel 1 for Motor B, 5 kHz frequency, 8-bit resolution
ledcAttachPin(L2PWM, L2);
}
void loop() {
while (serialBT.available()) {
btSignal = serialBT.read();
// Serial.println(btSignal);
if (btSignal == '0') Speed = 100;
if (btSignal == '1') Speed = 110;
if (btSignal == '2') Speed = 120;
if (btSignal == '3') Speed = 130;
if (btSignal == '4') Speed = 140;
if (btSignal == '5') Speed = 150;
if (btSignal == '6') Speed = 180;
if (btSignal == '7') Speed = 200;
if (btSignal == '8') Speed = 220;
if (btSignal == '9') Speed = 240;
if (btSignal == 'q') Speed = 255;
if (btSignal == 'F') // forward
{
ledcWrite(R1, Speed);
ledcWrite(R2, 0);
ledcWrite(L1, Speed);
ledcWrite(L2, 0);
}
else if (btSignal == 'B') // backward
{
ledcWrite(R1, 0);
ledcWrite(R2, Speed);
ledcWrite(L1, 0);
ledcWrite(L2, Speed);
}
else if (btSignal == 'L') // LEFT
{
ledcWrite(R1, 0);
ledcWrite(R2, Speed);
ledcWrite(L1, Speed);
ledcWrite(L2, 0);
}
else if (btSignal == 'R') // RIGHT
{
ledcWrite(R1, Speed);
ledcWrite(L1, 0);
ledcWrite(R2, 0);
ledcWrite(L2, Speed);
}
else if (btSignal == 'S') // STOP
{
ledcWrite(R1, 0);
ledcWrite(L1, 0);
ledcWrite(R2, 0);
ledcWrite(L2, 0);
}
else if (btSignal == 'I') // FORWARD RIGHT
{
ledcWrite(R1, Speed);
ledcWrite(R2, 0);
ledcWrite(L1, 0);
ledcWrite(L2, 0);
}
else if (btSignal == 'J') // BACKWARD RIGHT
{
ledcWrite(R1, 0);
ledcWrite(R2, Speed);
ledcWrite(L1, 0);
ledcWrite(L2, 0);
}