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

Bluetooth-Controlled Robotic Vehicle with Arduino and L298N Motor Driver

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

Circuit Documentation

Summary

This circuit is designed to control two DC motors using an L298N DC motor driver, which is interfaced with an Arduino UNO microcontroller. The Arduino UNO also connects to an HC-SR04 Ultrasonic Sensor for distance measurement and a Bluetooth HC-06 module for wireless communication, likely for remote control purposes. The circuit is powered by a 12V 7Ah battery. The microcontroller receives commands via Bluetooth to drive the motors in various directions (forward, backward, left, right) or to stop them.

Component List

L298N DC Motor Driver

DC Motor (x2)

Arduino UNO

Bluetooth HC-06

12V 7Ah Battery

HC-SR04 Ultrasonic Sensor

Mobile Phone

Wiring Details

L298N DC Motor Driver

DC Motors

Arduino UNO

Bluetooth HC-06

HC-SR04 Ultrasonic Sensor

Documented Code

// Pin Definitions
#define in1 8
#define in2 9
#define in3 10
#define in4 11
#define enA 5
#define enB 6

// Variables
char command = 'S';  // Default command is 'Stop'

void setup() {
  // Motor pins setup
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  
  // Set initial motor speed
  analogWrite(enA, 255);
  analogWrite(enB, 255);
  
  // Initialize Serial communication (for Bluetooth)
  Serial.begin(9600);
}

void loop() {
  // Check if data is available on Serial (Bluetooth)
  if (Serial.available() > 0) {
    command = Serial.read();  // Read the incoming command
    Serial.println(command);  // Print the received command for debugging
    
    // Execute the corresponding command
    if (command == 'F') {      // Forward
      forward();
    } else if (command == 'B') { // Backward
      backward();
    } else if (command == 'L') { // Left
      left();
    } else if (command == 'R') { // Right
      right();
    } else if (command == 'S') { // Stop
      stop();
    }
  }
}

// Functions to control the motors
void forward() {
  Serial.println("Forward");  // Debugging print
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
}

void backward() {
  Serial.println("Backward");  // Debugging print
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
}

void left() {
  Serial.println("Left");  // Debugging print
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
}

void right() {
  Serial.println("Right");  // Debugging print
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
}

void stop() {
  Serial.println("Stop");  // Debugging print
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

The code is written for the Arduino UNO and controls the L298N DC motor driver based on serial commands received from the Bluetooth HC-06 module. It defines motor control functions for moving forward, backward, turning left, and right, as well as stopping the motors. The loop function listens for incoming serial data and calls the appropriate motor control function based on the received command.