Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Controlled Bluetooth Robotic Vehicle with MT3608 Boost Converters and L298N Motor Drivers

View and Edit Project In Cirkit DesignerImage of ESP32-Controlled Bluetooth Robotic Vehicle with MT3608 Boost Converters and L298N Motor Drivers

Circuit Documentation

Summary

This circuit is designed to control a set of DC motors and a servo motor using an ESP32 microcontroller. The ESP32 is interfaced with an L298N DC motor driver to control the direction and speed of the motors. The circuit also includes MT3608 step-up converters to boost the voltage from a 4 x AAA battery mount to the required level for the motors and the motor driver. A toggle switch is used to control the power flow to the ESP32. The ESP32 is programmed to receive Bluetooth commands to control the movement of the motors, enabling wireless control of the system.

Component List

Microcontroller

Power Management

Motor Control

User Interface

Miscellaneous

Wiring Details

ESP32 (30 pin)

MT3608

L298N DC Motor Driver

MG996R

4 x AAA Battery Mount

DC Motor

Toggle Switch

Documented Code

#include "BluetoothSerial.h"

#define motor1Pin1  14
#define motor1Pin2  22
#define motor1Enable  23
#define motor2Pin1  5
#define motor2Pin2  2
#define motor2Enable  4
#define motor3Pin1  15
#define motor3Pin2  19
#define motor3Enable  21
const int canalPWM = 0; // Canal PWM
const int freq = 5000;  // Frequência do PWM
const int resolucao = 8; //resolução do PWM

BluetoothSerial SeriallBT;
char comando; //criação de uma variável para comandar o carro através do bluettoth

void setup() {
    // Inicializando o Bluetooth
    Serial.begin(9600);
    SeriallBT.begin("Carrinho");

    // Configura o canal PWM
    ledcSetup(canalPWM, freq, resolucao);
    // Anexa o pino ao canal PWM (define pinoPWM or use the correct pin)
    // ledcAttachPin(pinoPWM, canalPWM);

    // Inicializando pinos como output
    pinMode(motor1Pin1, OUTPUT);
    pinMode(motor1Pin2, OUTPUT);
    pinMode(motor1Enable, OUTPUT);
    pinMode(motor2Pin1, OUTPUT);
    pinMode(motor2Pin2, OUTPUT);
    pinMode(motor2Enable, OUTPUT);
    pinMode(motor3Pin1, OUTPUT);
    pinMode(motor3Pin2, OUTPUT);
    pinMode(motor3Enable, OUTPUT);
}

void loop() {
    if (SeriallBT.available()) {
        comando = SeriallBT.read();
    }

    switch (comando) {
        case 'F': // Mover frente
            MoveFoward();
            break;
        case 'B': // Mover trás
            MoveBackward();
            break;
        case 'G': // Frente esquerda
            MoveFowardLeft();
            break;
        case 'I': // Frente direita
            MoveFowardRight();
            break;
        case 'H': // Mover trás esquerda
            MoveBackwardLeft();
            break;
        case 'J': // Mover trás direita
            MoveBackwardRight();
            break;
    }
}

void MoveFoward() {
    analogWrite(motor2Enable, 255);
    analogWrite(motor3Enable, 255);
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH); // Sentido antihorário 1
    digitalWrite(motor3Pin1, HIGH); // Sentido horário 2
    digitalWrite(motor3Pin2, LOW);
}

void MoveBackward() {
    analogWrite(motor2Enable, 255);
    analogWrite(motor3Enable, 255);
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, HIGH); //sentido horário 1
    digitalWrite(motor2Pin2, LOW); 
    digitalWrite(motor3Pin1, LOW);
    digitalWrite(motor3Pin2, HIGH); // Sentido antihoráro 2
}

void MoveFowardLeft() {
    analogWrite(motor2Enable, 255);
    analogWrite(motor1Enable, 255);
    digitalWrite(motor1Pin1, HIGH); // Sentido horário 1
    digitalWrite(motor1Pin2, LOW); 
    digitalWrite(motor2Pin1, LOW); 
    digitalWrite(motor2Pin2, HIGH); // Sentido antihorário 2
    digitalWrite(motor3Pin1, LOW);
    digitalWrite(motor3Pin2, LOW);
}

void MoveFowardRight() {
    analogWrite(motor3Enable, 255);
    analogWrite(motor1Enable, 255);
    digitalWrite(motor1Pin1, LOW); 
    digitalWrite(motor1Pin2, HIGH);// Sentido antihorário
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, LOW);
    digitalWrite(motor3Pin1, HIGH); // Sentido horário
    digitalWrite(motor3Pin2, LOW);
}

void MoveBackwardLeft() {
    analogWrite(motor3Enable, 255);
    analogWrite(motor1Enable, 255);  
    digitalWrite(motor1Pin1, HIGH); // Sentido horário
    digitalWrite(motor1Pin2, LOW); 
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, LOW);
    digitalWrite(motor3Pin1, LOW);
    digitalWrite(motor3Pin2, HIGH); // Sentido antihorário
}

void MoveBackward