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

The circuit described is a Bluetooth-controlled car that uses an Arduino UNO as the main microcontroller to interface with an L298N DC motor driver and an HC-05 Bluetooth module. The L298N motor driver is responsible for driving four motors attached to the wheels of the car. The HC-05 Bluetooth module enables wireless control through Bluetooth communication. The car is powered by a 12V battery, which supplies power to the motor driver and, through a voltage regulator, to the Arduino UNO.

Component List

L298N DC Motor Driver

  • Description: A motor driver module capable of driving up to four DC motors with a maximum current of 2A per channel.
  • 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, widely used for building digital devices and interactive objects.
  • 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, typically used for serial port replacement.
  • Pins: EN, VCC, GND, TXD, RXD, STATE

Battery 12V

  • Description: A 12V battery used to provide power to the circuit.
  • Pins: +, -

Motor and Wheels (4 instances)

  • Description: DC motors connected to wheels, used for the motion of the car.
  • Pins: VCC, GND

Wiring Details

L298N DC Motor Driver

  • OUT1, OUT2 connected to two motors (motor and wheels)
  • 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 (motor and wheels)
  • 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 GND and HC-05 GND
  • Vin connected to L298N 5V
  • D6 connected to L298N ENA
  • D4 connected to L298N IN1
  • D7 connected to L298N IN2
  • D8 connected to L298N IN3
  • D9 connected to L298N IN4
  • D5 connected to L298N ENB
  • 5V connected to HC-05 VCC
  • D1 connected to HC-05 RXD
  • D0 connected to HC-05 TXD

HC-05 Bluetooth Module

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

Battery 12V

    • connected to L298N 12V
    • connected to L298N GND

Motor and Wheels

  • Four instances of motors connected to L298N OUT1, OUT2, OUT3, and OUT4 respectively.

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 control the car via Bluetooth commands. The AFMotor library is used to interface with the motor driver. The forward, back, left, and right functions control the car's movements, and the Stop function halts the motors. Commands are received from the HC-05 Bluetooth module through the Arduino's serial interface.