Arduino UNO Bluetooth-Controlled Car with L298N Motor Driver
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This document provides a detailed overview of a Bluetooth-controlled car circuit. The circuit uses an Arduino UNO microcontroller to control a car via an L298N motor driver and an HC-05 Bluetooth module. The car can move forward, backward, turn left, and turn right based on commands received via Bluetooth. Additionally, it can control two LEDs for signaling purposes.
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
L298N DC Motor Driver
- Description: A dual H-Bridge motor driver module that allows control of the speed and direction of two DC motors.
- 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
HC-05 Bluetooth Module
- Description: A Bluetooth module that enables wireless communication between the Arduino and other Bluetooth-enabled devices.
- Pins: Key, VCC, GND, TXD, RXD, State
5V Battery
- Description: A power source providing 5V DC.
- Pins: +, -
Wiring Details
Arduino UNO
5V connected to:
- L298N DC Motor Driver: 12V
- 5V Battery: +
- HC-05 Bluetooth Module: VCC
GND connected to:
- L298N DC Motor Driver: GND
- 5V Battery: -
- HC-05 Bluetooth Module: GND
D6 connected to:
- L298N DC Motor Driver: IN1
D5 connected to:
- L298N DC Motor Driver: IN2
D4 connected to:
- L298N DC Motor Driver: IN3
D3 connected to:
- L298N DC Motor Driver: IN4
D1 connected to:
- HC-05 Bluetooth Module: RXD
D0 connected to:
- HC-05 Bluetooth Module: TXD
L298N DC Motor Driver
12V connected to:
- Arduino UNO: 5V
- 5V Battery: +
GND connected to:
- Arduino UNO: GND
- 5V Battery: -
IN1 connected to:
- Arduino UNO: D6
IN2 connected to:
- Arduino UNO: D5
IN3 connected to:
- Arduino UNO: D4
IN4 connected to:
- Arduino UNO: D3
HC-05 Bluetooth Module
VCC connected to:
- Arduino UNO: 5V
- 5V Battery: +
GND connected to:
- Arduino UNO: GND
RXD connected to:
- Arduino UNO: D1
TXD connected to:
- Arduino UNO: D0
5V Battery
+ connected to:
- Arduino UNO: 5V
- L298N DC Motor Driver: 12V
- HC-05 Bluetooth Module: VCC
- connected to:
- Arduino UNO: GND
- L298N DC Motor Driver: GND
Code Documentation
/*
* Arduino Sketch for Bluetooth Controlled Car
*
* This code allows an Arduino UNO to control a car using an L298N motor driver
* and an HC-05 Bluetooth module. The car can move forward, backward, turn left,
* and turn right based on commands received via Bluetooth. Additionally, it can
* control two LEDs for signaling purposes.
*/
char t = '\0'; // Initialize with a default value
void setup() {
// Motor pins
pinMode(13, OUTPUT); // Left motor forward
pinMode(12, OUTPUT); // Left motor reverse
pinMode(11, OUTPUT); // Right motor forward
pinMode(10, OUTPUT); // Right motor reverse
// LED pins
pinMode(9, OUTPUT); // Main LED
pinMode(8, OUTPUT); // Back LED
// Start serial communication at 9600 baud rate
Serial.begin(9600);
}
void loop() {
// Check if data is available from the HC-05 Bluetooth module
if (Serial.available()) {
t = Serial.read(); // Read the incoming character
// Execute command based on the received character
switch (t) {
case 'F': // Move forward
digitalWrite(13, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(10, LOW);
break;
case 'B': // Move backward
digitalWrite(13, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(10, HIGH);
break;
case 'L': // Turn left
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
break;
case 'R': // Turn right
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
break;
case 'W': // Turn main LED on
digitalWrite(9, HIGH);
break;
case 'w': // Turn main LED off
digitalWrite(9, LOW);
break;
case 'M': // Turn back LED on
digitalWrite(8, HIGH);
break;
case 'm': // Turn back LED off
digitalWrite(8, LOW);
break;
case 'S': // Stop all motors and LEDs
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
break;
default:
// Handle any unrecognized command if needed
break;
}
}
}
This code initializes the necessary pins for motor and LED control, sets up serial communication, and continuously checks for incoming Bluetooth commands to control the car's movements and LED states.