Circuit Documentation
Summary
This document provides a detailed overview of a Bluetooth-controlled car circuit. The circuit includes an Arduino UNO microcontroller, an L298N DC motor driver, a 12V battery, multiple motors with wheels, and an HC-05 Bluetooth module. The Arduino UNO is programmed to control the motors based on commands received via Bluetooth.
Component List
L298N DC Motor Driver
- Description: Dual H-Bridge motor driver
- 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: Microcontroller board based on the ATmega328P
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
HC-05 Bluetooth Module
- Description: Bluetooth module for wireless communication
- Pins: EN, VCC, GND, TXD, RXD, STATE
Battery 12V
- Description: Power source
- Pins: +, -
Motor and Wheels
- Description: DC motors with attached wheels
- Pins: vcc, GND
Wiring Details
L298N DC Motor Driver
- OUT1 connected to vcc of Motor and Wheels
- OUT2 connected to GND of Motor and Wheels
- 12V connected to + of Battery 12V
- GND connected to - of Battery 12V and GND of Arduino UNO
- 5V connected to Vin of Arduino UNO
- OUT3 connected to GND of Motor and Wheels
- OUT4 connected to vcc of Motor and Wheels
- ENA connected to D6 of Arduino UNO
- IN1 connected to D4 of Arduino UNO
- IN2 connected to D7 of Arduino UNO
- IN3 connected to D8 of Arduino UNO
- IN4 connected to D9 of Arduino UNO
- ENB connected to D5 of Arduino UNO
Arduino UNO
- GND connected to - of Battery 12V and GND of L298N DC Motor Driver
- Vin connected to 5V of L298N DC Motor Driver
- D6 connected to ENA of L298N DC Motor Driver
- D4 connected to IN1 of L298N DC Motor Driver
- D7 connected to IN2 of L298N DC Motor Driver
- D8 connected to IN3 of L298N DC Motor Driver
- D9 connected to IN4 of L298N DC Motor Driver
- D5 connected to ENB of L298N DC Motor Driver
- 5V connected to VCC of HC-05 Bluetooth Module
- GND connected to GND of HC-05 Bluetooth Module
- D1 connected to RXD of HC-05 Bluetooth Module
- D0 connected to TXD of HC-05 Bluetooth Module
HC-05 Bluetooth Module
- VCC connected to 5V of Arduino UNO
- GND connected to GND of Arduino UNO
- RXD connected to D1 of Arduino UNO
- TXD connected to D0 of Arduino UNO
Battery 12V
- + connected to 12V of L298N DC Motor Driver
- - connected to GND of Arduino UNO and GND of L298N DC Motor Driver
Motor and Wheels
- vcc connected to OUT1 of L298N DC Motor Driver
- GND connected to OUT2 of L298N DC Motor Driver
- vcc connected to OUT4 of L298N DC Motor Driver
- GND connected to OUT3 of L298N DC Motor Driver
Documented Code
Arduino UNO 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); //rotate the motor clockwise
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
}
Arduino Mega 2560 Code
void setup() {
// put your setup code here, to run once:
}
void loop()
