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

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

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

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a set of DC motors using an L298N motor driver, which is interfaced with an Arduino UNO microcontroller. The Arduino UNO receives commands via a Bluetooth connection through the HC-05 Bluetooth Module to drive the motors in various directions (forward, backward, left, right) and to stop them. The circuit also includes a relay module to control additional DC motors, a battery to provide power, an LED indicator, and a rocker switch to control the power supply.

Component List

L298N DC Motor Driver

Hobby Gearmotor with 48:1 Gearbox

Battery 12V

Relay 4 Channel 5V

DC Motor

LED: Two Pin (Green)

Rocker Switch

Arduino UNO

HC-05 Bluetooth Module

Wiring Details

L298N DC Motor Driver

Hobby Gearmotor with 48:1 Gearbox

Battery 12V

Relay 4 Channel 5V

DC Motor

LED: Two Pin (Green)

Rocker Switch

Arduino UNO

HC-05 Bluetooth Module

Documented Code

Arduino UNO Code

// Pin Definitions
#define IN1 7
#define IN2 6
#define IN3 5
#define IN4 4
#define ENA 10
#define ENB 9

char command; // Stores the received command via Bluetooth

void setup() {
  // Motor driver pins setup
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  // Initialize Serial communication for Bluetooth
  Serial.begin(9600);
}

void loop() {
  // Check if there is data received via Bluetooth
  if (Serial.available() > 0) {
    command = Serial.read(); // Read the command from Bluetooth
    
    switch (command) {
      case 'F': // Move Forward
        moveForward();
        Serial.println("carForward");
        break;
        
      case 'B': // Move Backward
        moveBackward();
        Serial.println("carBACKWARD");
        break;
        
      case 'L': // Turn Left
        turnLeft();
        Serial.println("carLEFT");
        break;
        
      case 'R': // Turn Right
        turnRight();
        Serial.println("carRIGHT");
        break;
        
      case 'S': // Stop
        stopCar();
        break;
        
      default:
        stopCar(); // Stop if the command is not recognized
    }
  }
}

// Function to move the car forward
void moveForward() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  analogWrite(ENA, 255); // Full speed
  analogWrite(ENB, 255); // Full speed
}

// Function to move the car backward
void moveBackward() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  analogWrite(ENA, 255); // Full speed
  analogWrite(ENB, 255); // Full speed
}

// Function to turn the car left
void turnLeft() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  analogWrite(ENA, 255); // Full speed
  analogWrite(ENB, 255); // Full speed
}

// Function to turn the car right
void turnRight() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  analogWrite(ENA, 255); // Full speed
  analogWrite(ENB, 255); // Full speed
}

// Function to stop the car
void stopCar() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  analogWrite(ENA, 0); // Stop
  analogWrite(ENB, 0); // Stop
}

(Note: The code for the L298N DC motor driver microcontroller instance is empty and thus not included in the documentation.)