Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO and HC-05 Bluetooth Controlled Robotic Car with L298N Motor Driver

View and Edit Project In Cirkit DesignerImage of Arduino UNO and HC-05 Bluetooth Controlled Robotic Car with L298N Motor Driver

Circuit Documentation

Summary

This document provides a detailed overview of a Bluetooth-controlled motor driver circuit. The circuit consists of an Arduino UNO microcontroller, an HC-05 Bluetooth module, an L298N DC motor driver, two motors with wheels, and a 9V battery. The Arduino UNO is programmed to receive commands via Bluetooth to control the motors' movements.

Component List

9V Battery

HC-05 Bluetooth Module

Arduino UNO

Motor and Wheels

L298N DC Motor Driver

Wiring Details

9V Battery

HC-05 Bluetooth Module

Arduino UNO

L298N DC Motor Driver

Motor and Wheels

Documented Code

#include <SoftwareSerial.h>

// Motor driver pin definitions
int motor1_pin1 = 5;  // Motor 1 input pin 1
int motor1_pin2 = 4;  // Motor 1 input pin 2
int motor2_pin1 = 3;  // Motor 2 input pin 1
int motor2_pin2 = 2;  // Motor 2 input pin 2
int ENA = 10;         // Motor 1 Enable pin (for PWM control)
int ENB = 9;          // Motor 2 Enable pin (for PWM control)

// Bluetooth
SoftwareSerial BTSerial(11, 12);  // RX, TX pins for Bluetooth (adjust according to your wiring)
char Incoming_value = 0; // Variable to store incoming Bluetooth data

void setup() {
  // Pin modes for motor driver
  pinMode(motor1_pin1, OUTPUT);
  pinMode(motor1_pin2, OUTPUT);
  pinMode(motor2_pin1, OUTPUT);
  pinMode(motor2_pin2, OUTPUT);

  // Enable motor driver (for motor control)
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  digitalWrite(ENA, HIGH);  // Enable motor 1
  digitalWrite(ENB, HIGH);  // Enable motor 2

  // Start serial communication at 9600 baud rate
  Serial.begin(9600);  // Serial monitor
  BTSerial.begin(9600);  // Bluetooth communication

  Serial.println("Motor Control Program Started");
  Serial.println("Send commands via Bluetooth: F = Forward, B = Backward, L = Left, R = Right, S = Stop");
}

void loop() {
  // Check if there's any data coming in from the Serial Monitor
  if (Serial.available() > 0) {
    Incoming_value = Serial.read();  // Read the incoming byte
    processCommand(Incoming_value);
  }

  // Check if there's any data coming in from the Bluetooth module
  if (BTSerial.available() > 0) {
    Incoming_value = BTSerial.read();  // Read the incoming byte
    Serial.print("Received command from Bluetooth: ");
    Serial.println(Incoming_value); // Debugging output
    processCommand(Incoming_value);
  }
}

// Function to process incoming commands
void processCommand(char command) {
  // Check the command and control the motors accordingly
  if (command == 'F') { // Forward
    Serial.println("Moving Forward");
    digitalWrite(motor1_pin1, LOW);
    digitalWrite(motor1_pin2, HIGH);
    digitalWrite(motor2_pin1, LOW);
    digitalWrite(motor2_pin2, HIGH);
  } 
  else if (command == 'B') { // Backward
    Serial.println("Moving Backward");
    digitalWrite(motor1_pin1, HIGH);
    digitalWrite(motor1_pin2, LOW);
    digitalWrite(motor2_pin1, HIGH);
    digitalWrite(motor2_pin2, LOW);
  } 
  else if (command == 'L') { // Left
    Serial.println("Turning Left");
    digitalWrite(motor1_pin1, LOW);
    digitalWrite(motor1_pin2, LOW);
    digitalWrite(motor2_pin1, LOW);
    digitalWrite(motor2_pin2, HIGH);
  } 
  else if (command == 'R') { // Right
    Serial.println("Turning Right");
    digitalWrite(motor1_pin1, HIGH);
    digitalWrite(motor1_pin2, LOW);
    digitalWrite(motor2_pin1, LOW);
    digitalWrite(motor2_pin2, LOW);
  } 
  else if (command == 'S') { // Stop
    Serial.println("Stopping Motors");
    digitalWrite(motor1_pin1, LOW);
    digitalWrite(motor1_pin2, LOW);
    digitalWrite(motor2_pin1, LOW);
    digitalWrite(motor2_pin2, LOW);
  }
  else {
    Serial.println("Invalid Command");
  }
}