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

Arduino-Controlled Bluetooth Robotic Car

Image of Arduino-Controlled Bluetooth Robotic Car

Circuit Documentation

Summary

This circuit is designed to control a car via Bluetooth using an Arduino UNO as the main microcontroller. The car is powered by a 12V battery and features four motors with wheels for movement. The L298N DC motor driver is used to control the direction and speed of the motors. Communication with the car is facilitated by the HC-05 Bluetooth module, which receives commands from a Bluetooth-enabled device.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P
  • Used for processing and executing commands received via Bluetooth
  • Interfaces with the motor driver and Bluetooth module

L298N DC Motor Driver

  • Dual H-Bridge motor driver
  • Capable of driving two DC motors or one stepper motor
  • Used to control the direction and speed of the motors

HC-05 Bluetooth Module

  • Bluetooth to serial converter module
  • Enables wireless communication with the Arduino
  • Receives commands from a Bluetooth-enabled device

Battery 12V

  • Provides power to the circuit
  • Supplies the motor driver with the necessary voltage for motor operation

Motors and Wheels (4x)

  • DC motors connected to wheels
  • Provide movement to the car
  • Controlled by the motor driver

Comments

  • Placeholder components for additional notes or documentation

Wiring Details

Arduino UNO

  • Vin connected to L298N DC motor driver 5V for power
  • GND connected to battery - and L298N DC motor driver GND for common ground
  • 5V connected to HC-05 VCC for Bluetooth module power
  • D0 (RX) connected to HC-05 TXD for Bluetooth communication
  • D1 (TX) connected to HC-05 RXD for Bluetooth communication
  • D4 connected to L298N IN1 for motor control
  • D5 connected to L298N ENB for motor enable
  • D6 connected to L298N ENA for motor enable
  • D7 connected to L298N IN2 for motor control
  • D8 connected to L298N IN3 for motor control
  • D9 connected to L298N IN4 for motor control

L298N DC Motor Driver

  • 12V connected to battery + for power
  • OUT1 and OUT2 connected to one pair of motors and wheels
  • OUT3 and OUT4 connected to another pair of motors and wheels
  • ENA and ENB connected to Arduino for enabling motor outputs
  • IN1, IN2, IN3, IN4 connected to Arduino for motor direction control

HC-05 Bluetooth Module

  • VCC connected to Arduino 5V for power
  • GND connected to Arduino GND for common ground
  • TXD connected to Arduino D0 (RX) for Bluetooth communication
  • RXD connected to Arduino D1 (TX) for Bluetooth communication

Battery 12V

  • + connected to L298N 12V for motor power
  • - connected to Arduino GND and L298N GND for common ground

Motors and Wheels

  • Four motors each with two connections: vcc and GND
  • Each motor's vcc and GND connected to corresponding OUT pins on the L298N motor driver

Documented Code

//Arduino Bluetooth Controlled Car
//Before uploading the code you have to install the necessary library
//Note - Disconnect the Bluetooth Module before hitting the upload button otherwise you'll get a compilation error message.
//AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install 
//After downloading the library open Arduino IDE >> go to sketch >> Include Library >> ADD. ZIP Library >> Select the downloaded 
//ZIP File >> Open it >> Done
//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.   
    //Serial.println(command);
    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 simplify the control of the motors connected to the L298N motor driver. Commands are sent as single characters ('F' for forward, 'B' for backward, 'L' for left, and 'R' for right) from a Bluetooth-enabled device to the HC-05 module, which are then read by the Arduino and executed.