Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Controlled Bluetooth Car with L298N Motor Driver

Image of Arduino-Controlled Bluetooth Car with L298N Motor Driver

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a four-wheeled vehicle using an Arduino UNO microcontroller and a Bluetooth module (HC-05) for wireless communication. The vehicle's motion is driven by four DC motors, which are controlled by an L298N DC motor driver. The motors are powered by a 12V battery. The Arduino UNO receives commands via Bluetooth and controls the motor driver to move the vehicle forward, backward, turn left, and turn right.

Component List

L298N DC Motor Driver

  • Description: A module capable of driving up to two DC motors with control over speed and direction.
  • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, ENA, IN1, IN2, IN3, IN4, ENB

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P, widely used for building digital devices and interactive objects.
  • Pins: IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13

HC-05 Bluetooth Module

  • Description: A Bluetooth module for wireless communication, typically used for serial port replacement.
  • Pins: EN, VCC, GND, TXD, RXD, STATE

12V Battery

  • Description: A power source for the circuit, providing the necessary voltage to drive the motors.
  • Pins: +, -

Motor and Wheels (x4)

  • Description: DC motors attached to wheels, providing the motion for the vehicle.
  • Pins: VCC, GND

Wiring Details

L298N DC Motor Driver

  • OUT1, OUT2 connected to Motor 1
  • OUT3, OUT4 connected to Motor 2
  • 12V connected to the positive terminal of the 12V battery
  • GND connected to the GND of Arduino UNO and negative terminal of the 12V battery
  • 5V connected to the Vin of Arduino UNO
  • ENA connected to D6 of Arduino UNO
  • IN1 connected to D4 of Arduino UNO
  • IN2 connected to D7 of Arduino UNO
  • IN3 connected to D8 of Arduino UNO
  • IN4 connected to D9 of Arduino UNO
  • ENB connected to D5 of Arduino UNO

Arduino UNO

  • GND connected to GND of L298N DC Motor Driver and HC-05 Bluetooth Module
  • Vin connected to 5V of L298N DC Motor Driver
  • 5V connected to VCC of HC-05 Bluetooth Module
  • D0 connected to TXD of HC-05 Bluetooth Module
  • D1 connected to RXD of HC-05 Bluetooth Module
  • D4-D9 connected to IN1-IN4 and ENA, ENB of L298N DC Motor Driver

HC-05 Bluetooth Module

  • VCC connected to 5V of Arduino UNO
  • GND connected to GND of Arduino UNO
  • TXD connected to D0 of Arduino UNO
  • RXD connected to D1 of Arduino UNO

12V Battery

    • connected to 12V of L298N DC Motor Driver
    • connected to GND of L298N DC Motor Driver

Motor and Wheels

  • Each motor's VCC connected to OUT1/OUT3 of L298N DC Motor Driver
  • Each motor's GND connected to OUT2/OUT4 of L298N DC Motor Driver

Documented Code

//Arduino Bluetooth Controlled Car
//Before uploading the code you have to install the necessary library
//AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install
//Now You Can Upload the Code without any problem but make sure the bt module isn't connected with Arduino while uploading code

#include <AFMotor.h>

//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ); 
AF_DCMotor motor2(2, MOTOR12_1KHZ); 
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

char command; 

void setup() 
{       
  Serial.begin(9600);  //Set the baud rate to your Bluetooth module.
}

void loop(){
  if(Serial.available() > 0){ 
    command = Serial.read(); 
    Stop(); //initialize with motors stopped
    //Change pin mode only if new command is different from previous.
    switch(command){
    case 'F':  
      forward();
      break;
    case 'B':  
       back();
      break;
    case 'L':  
      left();
      break;
    case 'R':
      right();
      break;
    }
  } 
}

void forward()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(255);//Define maximum velocity
  motor3.run(FORWARD); //rotate the motor clockwise
  motor4.setSpeed(255);//Define maximum velocity
  motor4.run(FORWARD); //rotate the motor clockwise
}

void back()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}

void left()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(FORWARD);  //rotate the motor clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(FORWARD);  //rotate the motor clockwise
}

void right()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
} 

void Stop()
{
  motor1.setSpeed(0); //Define minimum velocity
  motor1.run(RELEASE); //stop the motor when release the button
  motor2.setSpeed(0); //Define minimum velocity
  motor2.run(RELEASE); //stop the motor when release the button
  motor3.setSpeed(0); //Define minimum velocity
  motor3.run(RELEASE); //stop the motor when release the button
  motor4.setSpeed(0); //Define minimum velocity
  motor4.run(RELEASE); //stop the motor when release the button
}

This code is designed to be uploaded to an Arduino UNO microcontroller. It includes a library for controlling DC motors, defines motor objects, and sets up a serial communication with the HC-05 Bluetooth module. The loop function listens for incoming serial data, interprets the commands, and calls the appropriate movement functions (forward, back, left, right, Stop) to control the motors accordingly.