

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.
Vin connected to L298N DC motor driver 5V for powerGND connected to battery - and L298N DC motor driver GND for common ground5V connected to HC-05 VCC for Bluetooth module powerD0 (RX) connected to HC-05 TXD for Bluetooth communicationD1 (TX) connected to HC-05 RXD for Bluetooth communicationD4 connected to L298N IN1 for motor controlD5 connected to L298N ENB for motor enableD6 connected to L298N ENA for motor enableD7 connected to L298N IN2 for motor controlD8 connected to L298N IN3 for motor controlD9 connected to L298N IN4 for motor control12V connected to battery + for powerOUT1 and OUT2 connected to one pair of motors and wheelsOUT3 and OUT4 connected to another pair of motors and wheelsENA and ENB connected to Arduino for enabling motor outputsIN1, IN2, IN3, IN4 connected to Arduino for motor direction controlVCC connected to Arduino 5V for powerGND connected to Arduino GND for common groundTXD connected to Arduino D0 (RX) for Bluetooth communicationRXD connected to Arduino D1 (TX) for Bluetooth communication+ connected to L298N 12V for motor power- connected to Arduino GND and L298N GND for common groundvcc and GNDvcc and GND connected to corresponding OUT pins on the L298N motor driver//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.