Arduino UNO Bluetooth-Controlled Robotic Car with Motor Drivers and Servos
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This document provides a detailed overview of a circuit designed to control a Bluetooth-enabled car using an Arduino UNO. The circuit includes various components such as motors, a motor driver, a Bluetooth module, and micro servos. The Arduino UNO is programmed to receive commands via Bluetooth and control the motors accordingly.
Component List
Arduino UNO
- Description: A 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
Motor with reducer
- Description: A DC motor with a built-in reducer.
- Pins: 3 - 6 VCC, GND
L298N DC motor driver
- Description: A 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
Battery 12V
- Description: A 12V battery for powering the circuit.
- Pins: +, -
Micro servo 9G
- Description: A small servo motor.
- Pins: GND, +5V, PWM
HC-05 Bluetooth Module
- Description: A Bluetooth module for wireless communication.
- Pins: Key, VCC, TXD, RXD, State, GND
Wiring Details
Arduino UNO
- 5V connected to VCC of HC-05 Bluetooth Module.
- GND connected to GND of HC-05 Bluetooth Module.
- D3 connected to TXD of HC-05 Bluetooth Module.
- D2 connected to RXD of HC-05 Bluetooth Module.
- Vin connected to 5V of L298N DC motor driver and - of battery 12V.
- GND connected to GND of L298N DC motor driver and GND of all Micro servo 9G motors.
- D12 connected to IN3 of L298N DC motor driver.
- D11 connected to IN2 of L298N DC motor driver.
- D10 connected to ENB of L298N DC motor driver.
- D9 connected to ENA of L298N DC motor driver.
- D8 connected to IN1 of L298N DC motor driver.
- D7 connected to IN4 of L298N DC motor driver.
- D6 connected to PWM of one Micro servo 9G motor.
- D5 connected to PWM of another Micro servo 9G motor.
- D4 connected to PWM of another Micro servo 9G motor.
- D1 connected to PWM of another Micro servo 9G motor.
Motor with reducer
- 3 - 6 VCC connected to OUT1 of L298N DC motor driver.
- GND connected to OUT2 of L298N DC motor driver.
- 3 - 6 VCC connected to OUT3 of L298N DC motor driver.
- GND connected to OUT4 of L298N DC motor driver.
L298N DC motor driver
- 5V connected to Vin of Arduino UNO and - of battery 12V.
- GND connected to GND of Arduino UNO.
- 12V connected to + of battery 12V.
- IN3 connected to D12 of Arduino UNO.
- IN2 connected to D11 of Arduino UNO.
- ENB connected to D10 of Arduino UNO.
- ENA connected to D9 of Arduino UNO.
- IN1 connected to D8 of Arduino UNO.
- IN4 connected to D7 of Arduino UNO.
- OUT1 connected to 3 - 6 VCC of one Motor with reducer.
- OUT2 connected to GND of one Motor with reducer.
- OUT3 connected to 3 - 6 VCC of another Motor with reducer.
- OUT4 connected to GND of another Motor with reducer.
Battery 12V
- + connected to 12V of L298N DC motor driver.
- - connected to 5V of L298N DC motor driver and Vin of Arduino UNO.
Micro servo 9G
- +5V of all Micro servo 9G motors are connected together.
- GND of all Micro servo 9G motors are connected together and to GND of Arduino UNO.
- PWM of each Micro servo 9G motor is connected to different digital pins on Arduino UNO (D6, D5, D4, D1).
HC-05 Bluetooth Module
- VCC connected to 5V of Arduino UNO.
- GND connected to GND of Arduino UNO.
- TXD connected to D3 of Arduino UNO.
- RXD connected to D2 of Arduino UNO.
Code Documentation
#include <SoftwareSerial.h>
// Bluetooth module connected to pins 2 (RX) and 3 (TX)
SoftwareSerial mySerial(2, 3);
// Motor driver pins
int Rightmotor1 = 4;
int Rightmotor2 = 5;
int leftmotor1 = 6;
int leftmotor2 = 7;
int en1 = 9;
int en2 = 10;
// String to hold incoming Bluetooth data
String command = "";
void setup() {
// Initialize motor pins
pinMode(Rightmotor1, OUTPUT);
pinMode(Rightmotor2, OUTPUT);
pinMode(leftmotor1, OUTPUT);
pinMode(leftmotor2, OUTPUT);
pinMode(en1, OUTPUT);
pinMode(en2, OUTPUT);
// Start serial communication for debugging and Bluetooth
Serial.begin(9600);
mySerial.begin(9600);
Serial.println("Bluetooth Car Ready!");
}
void loop() {
if (mySerial.available()) {
char received = mySerial.read(); // Read the single character command
if (received == 'F') {
moveForward(); // Move forward
} else if (received == 'B') {
moveBackward(); // Move backward
} else if (received == 'L') {
turnLeft(); // Turn left
} else if (received == 'R') {
turnRight(); // Turn right
} else if (received == 'S') {
stopMotors(); // Stop
}
}
}
// Movement functions
void moveForward() {
digitalWrite(Rightmotor1, HIGH);
digitalWrite(Rightmotor2, LOW);
digitalWrite(leftmotor1, HIGH);
digitalWrite(leftmotor2, LOW);
analogWrite(en1, 200); // Adjust speed as needed (0-255)
analogWrite(en2, 200);
Serial.println("Moving Forward");
}
void moveBackward() {
digitalWrite(Rightmotor1, LOW);
digitalWrite(Rightmotor2, HIGH);
digitalWrite(leftmotor1, LOW);
digitalWrite(leftmotor2, HIGH);
analogWrite(en1, 200);
analogWrite(en2, 200);
Serial.println("Moving Backward");
}
void turnLeft() {
digitalWrite(Rightmotor1, HIGH);
digitalWrite(Rightmotor2, LOW);
digitalWrite(leftmotor1, LOW);
digitalWrite(leftmotor2, HIGH);
analogWrite(en1, 150); // Reduced speed for turning
analogWrite(en2, 150);
Serial.println("Turning Left");
}
void turnRight() {
digitalWrite(Rightmotor1, LOW);
digitalWrite(Rightmotor2, HIGH);
digitalWrite(leftmotor1, HIGH);
digitalWrite(leftmotor2, LOW);
analogWrite(en1, 150);
analogWrite(en2, 150);
Serial.println("Turning Right");
}
void stopMotors() {
digitalWrite(Rightmotor1, LOW);
digitalWrite(Rightmotor2, LOW);
digitalWrite(leftmotor1, LOW);
digitalWrite(leftmotor2, LOW);
analogWrite(en1, 0);
analogWrite(en2, 0);
Serial.println("Motors Stopped");
}
This code initializes the motor driver pins and sets up serial communication for both debugging and Bluetooth. The loop