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

Arduino UNO and L298N Motor Driver Based Bluetooth Controlled Car

Image of Arduino UNO and L298N Motor Driver Based Bluetooth Controlled Car

Circuit Documentation

Summary

This circuit is designed to control a car via Bluetooth using an Arduino UNO microcontroller. The car is powered by a 12V battery and features four motors with wheels. The motors are driven by an L298N DC motor driver, which receives control signals from the Arduino. A Bluetooth module (HC-05) is interfaced with the Arduino to receive commands wirelessly from a Bluetooth-enabled device.

Component List

L298N DC Motor Driver

  • Description: A module used to drive DC motors with direction and speed control.
  • 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

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Pins: UNUSED, 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.
  • Pins: EN, VCC, GND, TXD, RXD, STATE

12V Battery

  • Description: A power source for the circuit.
  • Pins: +, -

Motors and Wheels (x4)

  • Description: DC motors connected to wheels for the car's movement.
  • Pins: VCC, GND

Wiring Details

L298N DC Motor Driver

  • OUT1, OUT2 connected to two motors and wheels (vcc, GND)
  • 12V connected to the 12V battery (+)
  • GND connected to Arduino UNO (GND) and 12V battery (-)
  • 5V connected to Arduino UNO (Vin)
  • OUT3, OUT4 connected to two other motors and wheels (vcc, GND)
  • ENA connected to Arduino UNO (D6)
  • IN1 connected to Arduino UNO (D4)
  • IN2 connected to Arduino UNO (D7)
  • IN3 connected to Arduino UNO (D8)
  • IN4 connected to Arduino UNO (D9)
  • ENB connected to Arduino UNO (D5)

Arduino UNO

  • GND connected to L298N DC Motor Driver (GND) and HC-05 (GND)
  • Vin connected to L298N DC Motor Driver (5V)
  • 5V connected to HC-05 (VCC)
  • D0 connected to HC-05 (TXD)
  • D1 connected to HC-05 (RXD)
  • D4-D9 connected to L298N DC Motor Driver (IN1, IN2, IN3, IN4, ENA, ENB)

HC-05 Bluetooth Module

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

12V Battery

    • connected to L298N DC Motor Driver (12V)
    • connected to Arduino UNO (GND)

Motors and Wheels

  • Four sets of motors and wheels, each connected to the L298N DC Motor Driver (OUT1, OUT2, OUT3, OUT4)

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 receive commands via Bluetooth and control the motors accordingly to move the car forward, backward, left, or right. The AFMotor library is used to interface with the motor driver, and the Serial object is used for Bluetooth communication.