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

ESP32 Bluetooth-Controlled Dual Joystick Motor Driver System

View and Edit Project In Cirkit DesignerImage of ESP32 Bluetooth-Controlled Dual Joystick Motor Driver System

Circuit Documentation

Summary

This circuit involves two ESP32 microcontrollers, joystick modules, a toggle switch, motor drivers, DC motors, LEDs, resistors, and batteries. The primary function of the circuit is to read joystick inputs and control DC motors via Bluetooth communication between the two ESP32 microcontrollers. The circuit also includes LEDs for visual indication.

Component List

  1. Joystick Module

    • Pins: SW, VRY, VRX, VCC, GND
    • Description: Used to capture analog input from the joystick movements.
  2. Toggle Switch

    • Pins: Vcc, Sig, Gnd
    • Description: Used to toggle the power supply to the ESP32 microcontroller.
  3. TB6612FNG Motor Driver

    • Pins: GND, B01, B02, A02, A01, VCC, VM, PWMB, BI2, BI1, STBY, AI1, AI2, PWMA
    • Description: Used to control the DC motors based on the signals received from the ESP32 microcontroller.
  4. ESP32

    • 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
    • Description: Microcontroller used for Bluetooth communication and control logic.
  5. LED: Two Pin (green)

    • Pins: cathode, anode
    • Description: Used for visual indication.
  6. LED: Two Pin (red)

    • Pins: cathode, anode
    • Description: Used for visual indication.
  7. Lipo Battery 2200mAH 30c

    • Pins: VCC, GND
    • Description: Power supply for the motor driver and ESP32 microcontroller.
  8. Resistor (200 Ohms)

    • Pins: pin1, pin2
    • Description: Used to limit current to the LEDs.
  9. DC Mini Metal Gear Motor

    • Pins: IN1, IN2
    • Description: Used to drive mechanical components based on control signals.
  10. 9V Battery

    • Pins: -, +
    • Description: Power supply for the toggle switch and ESP32 microcontroller.

Wiring Details

Joystick Module 1

Joystick Module 2

Toggle Switch

TB6612FNG Motor Driver

LED: Two Pin (green)

LED: Two Pin (red)

Lipo Battery 2200mAH 30c

Resistor 1 (200 Ohms)

Resistor 2 (200 Ohms)

DC Mini Metal Gear Motor 1

DC Mini Metal Gear Motor 2

9V Battery

Code Documentation

ESP32 (Transmitter)

#include <BluetoothSerial.h>

BluetoothSerial SerialBT;

void setup() {
  pinMode(2, OUTPUT); // LED indicator
  Serial.begin(115200);
  SerialBT.begin("ESP32_Emisor"); // Bluetooth device name
  Serial.println("The Bluetooth device is ready to pair");
}

void loop() {
  int joy1X = analogRead(34);
  int joy1Y = analogRead(35);
  int joy2X = analogRead(32);
  int joy2Y = analogRead(33);

  String message = String(joy1X) + "," + String(joy1Y) + "," + String(joy2X) + "," + String(joy2Y);
  SerialBT.println(message);

  digitalWrite(2, HIGH); // Turn on the LED
  delay(100);
  digitalWrite(2, LOW); // Turn off the LED
  delay(100);
}

ESP32 (Receiver)

#include <BluetoothSerial.h>

BluetoothSerial SerialBT;

const int PWMA = 14;
const int AIN1 = 27;
const int AIN2 = 26;
const int PWMB = 25;
const int BIN1 = 33;
const int BIN2 = 32;

void setup() {
  pinMode(PWMA, OUTPUT);
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);
  pinMode(PWMB, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);
  pinMode(2, OUTPUT); // LED indicator

  Serial.begin(115200);
  SerialBT.begin("ESP32_Receptor");
  Serial.println("The Bluetooth device is ready to receive");
}

void loop() {
   if (SerialBT.available()) {
    String message = SerialBT.readStringUntil('\n');
    int commaCount = message.length() - message.replace(",", "").length();
    
    if (commaCount == 3) { // Ensure there are exactly 3 commas
      int joy1X = message.substring(0, message.indexOf(',')).toInt();
      message = message.substring(message.indexOf(',') + 1);
      int joy1Y = message.substring(0, message.indexOf(',')).toInt();
      message = message.substring(message.indexOf(',') + 1);
      int joy2X = message.substring(0, message.indexOf(',')).toInt();
      message = message.substring(message.indexOf(',') + 1);
      int joy2Y = message.toInt();

      // Example motor control logic
      analogWrite(PWMA, joy1X);
      digitalWrite(AIN1, joy1Y > 512 ? HIGH : LOW);
      digitalWrite(AIN2, joy1Y <= 512 ? HIGH : LOW);

      analogWrite(PWMB, joy2X);
      digitalWrite(BIN1, joy2Y > 512 ? HIGH : LOW);
      digitalWrite(BIN2, joy2Y <= 512 ? HIGH : LOW);

      digitalWrite(2, HIGH); // Turn on the LED
      delay(100);
      digitalWrite(2, LOW); // Turn off the LED
    } else {
      Serial.println("Error: Malformed message");
    }

    // Motor control logic based on joystick values
    // Add logic to control motors here

    digitalWrite(2, HIGH); // Turn on the LED
    delay(100);
    digitalWrite(2, LOW); // Turn off the LED
  }
}

This documentation provides a comprehensive overview of the circuit, including a summary, component list, wiring details, and code documentation.