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

Arduino-Controlled Bluetooth Robotic Car with L298N Motor Driver

Image of Arduino-Controlled Bluetooth Robotic Car with L298N Motor Driver

Circuit Documentation

Summary

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 Arduino UNO receives commands via Bluetooth and controls the motor driver to move the vehicle forward, backward, turn left, and turn right. The motors are powered by a 12V battery, which also supplies power to the motor driver. The Arduino is powered through its Vin pin by the 5V output from the motor driver.

Component List

  • L298N DC Motor Driver: A module used to control the speed and direction of two DC motors. It can drive up to 2A per channel.
  • Arduino UNO: A microcontroller board based on the ATmega328P. It has digital input/output pins, analog inputs, and a USB connection for programming and serial communication.
  • HC-05 Bluetooth Module: A wireless communication module that allows the Arduino to communicate with Bluetooth-enabled devices like smartphones.
  • 12V Battery: Provides the power source for the motor driver and indirectly for the Arduino UNO.
  • DC Motors and Wheels (4 sets): The actuators that move the vehicle. Each motor is connected to a wheel.

Wiring Details

L298N DC Motor Driver

  • OUT1, OUT2: Connected to two motors and wheels.
  • OUT3, OUT4: Connected to the other two motors and wheels.
  • 12V: Connected to the positive terminal of the 12V battery.
  • GND: Connected to the ground terminal of the 12V battery and Arduino UNO GND.
  • 5V: Provides power to the Arduino UNO Vin pin.
  • ENA, ENB: Connected to Arduino UNO digital pins for enabling motor control.
  • IN1, IN2, IN3, IN4: Connected to Arduino UNO digital pins for controlling motor direction.

Arduino UNO

  • Vin: Powered by the 5V output from the L298N motor driver.
  • GND: Common ground with the motor driver and the 12V battery.
  • Digital Pins (D4, D5, D6, D7, D8, D9): Control signals for the L298N motor driver.
  • Digital Pins (D0, D1): Serial communication with the HC-05 Bluetooth module.

HC-05 Bluetooth Module

  • VCC: Powered by the 5V output from the Arduino UNO.
  • GND: Common ground with the Arduino UNO.
  • TXD: Connected to Arduino UNO D0 (RX).
  • RXD: Connected to Arduino UNO D1 (TX).

12V Battery

  • +: Powers the L298N motor driver.
  • -: Common ground with the motor driver and Arduino UNO.

Motors and Wheels

  • vcc: Powered by the L298N motor driver outputs (OUT1, OUT2, OUT3, OUT4).
  • GND: Common ground with the 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 serial communication for receiving Bluetooth commands. The loop function checks for incoming serial data and executes movement commands accordingly. Functions forward, back, left, right, and Stop control the motors' speed and direction.