This document provides a detailed overview of a Bluetooth-controlled car circuit. The circuit consists of an Arduino UNO microcontroller, an L298N DC motor driver, four DC motors with wheels, an HC-05 Bluetooth module, and a 12V battery. The Arduino UNO is programmed to control the motors based on commands received via Bluetooth.
L298N DC Motor Driver
Arduino UNO
HC-05 Bluetooth Module
12V Battery
Motor and Wheels (4 units)
// 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
motor