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

ESP32 Wi-Fi Controlled Battery-Powered Robotic Car

View and Edit Project In Cirkit DesignerImage of ESP32 Wi-Fi Controlled Battery-Powered Robotic Car

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to control a set of DC motors using an ESP32 microcontroller and an L298N motor driver. The circuit is powered by a 9V battery and includes four motor and wheel assemblies. The ESP32 is programmed to control the motors based on serial input commands.

Component List

  1. ESP32 38 PINS

    • Description: A versatile microcontroller with Wi-Fi and Bluetooth capabilities.
    • Pins: GND, 23, 22/SCL, 1, 2, 21/SDA, 19, 18, 5, 17/TX2, 16/RX2, 4, 0, 15, D1, D0, CLK, 3V3, EN, VP, VN, 34, 35, 32, 33, 25, 26, 27, 14, 12, 13, D2, D3, 11, 5V/VIN
  2. 9V battery

    • Description: A standard 9V battery used to power the circuit.
    • Pins: +, -
  3. L298N DC motor driver

    • Description: A dual H-bridge motor driver that allows control of the speed and direction of two DC motors.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
  4. Motor and wheels (4 units)

    • Description: DC motors with attached wheels for movement.
    • Pins: vcc, GND

Wiring Details

ESP32 38 PINS

9V battery

L298N DC motor driver

Motor and wheels (4 units)

Documented Code

ESP32 38 PINS Code

#include <Arduino.h>
#include <driver/ledc.h> // Include the Arduino core for ESP32

// Right motor
int enableRightMotor = 22; 
int rightMotorPin1 = 16;
int rightMotorPin2 = 17;
// Left motor
int enableLeftMotor = 23;
int leftMotorPin1 = 18;
int leftMotorPin2 = 19;

#define MAX_MOTOR_SPEED 255

const int PWMFreq = 1000; /* 1 KHz */
const int PWMResolution = 8;
const int rightMotorPWMSpeedChannel = 4;
const int leftMotorPWMSpeedChannel = 5;

void rotateMotor(int rightMotorSpeed, int leftMotorSpeed)
{
  if (rightMotorSpeed < 0)
  {
    digitalWrite(rightMotorPin1, LOW);
    digitalWrite(rightMotorPin2, HIGH);    
  }
  else if (rightMotorSpeed > 0)
  {
    digitalWrite(rightMotorPin1, HIGH);
    digitalWrite(rightMotorPin2, LOW);      
  }
  else
  {
    digitalWrite(rightMotorPin1, LOW);
    digitalWrite(rightMotorPin2, LOW);      
  }
  
  if (leftMotorSpeed < 0)
  {
    digitalWrite(leftMotorPin1, LOW);
    digitalWrite(leftMotorPin2, HIGH);    
  }
  else if (leftMotorSpeed > 0)
  {
    digitalWrite(leftMotorPin1, HIGH);
    digitalWrite(leftMotorPin2, LOW);      
  }
  else
  {
    digitalWrite(leftMotorPin1, LOW);
    digitalWrite(leftMotorPin2, LOW);      
  }
  
  ledcWrite(rightMotorPWMSpeedChannel, abs(rightMotorSpeed));
  ledcWrite(leftMotorPWMSpeedChannel, abs(leftMotorSpeed));  
}

void setUpPinModes()
{
  pinMode(enableRightMotor, OUTPUT);
  pinMode(rightMotorPin1, OUTPUT);
  pinMode(rightMotorPin2, OUTPUT);
  
  pinMode(enableLeftMotor, OUTPUT);
  pinMode(leftMotorPin1, OUTPUT);
  pinMode(leftMotorPin2, OUTPUT);

  rotateMotor(0, 0); 
}

void setup() {
  setUpPinModes();
  Serial.begin(115200);
}

void loop() {
  if (Serial.available() > 0) {
    char input = Serial.read();
    switch (input) {
      case 'w':
        rotateMotor(MAX_MOTOR_SPEED / 2, MAX_MOTOR_SPEED / 2);
        break;
      case 's':
        rotateMotor(-MAX_MOTOR_SPEED / 2, -MAX_MOTOR_SPEED / 2);
        break;
      case 'a':
        rotateMotor(-MAX_MOTOR_SPEED / 2, MAX_MOTOR_SPEED / 2);
        break;
      case 'd':
        rotateMotor(MAX_MOTOR_SPEED / 2, -MAX_MOTOR_SPEED / 2);
        break;
      case 'x':
        rotateMotor(0, 0);
        break;
    }
  }
}

Motor and wheels Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

This concludes the documentation for the circuit.