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

Bluetooth-Controlled Arduino UNO Robot with Dual DC Motors and L298N Driver

View and Edit Project In Cirkit DesignerImage of Bluetooth-Controlled Arduino UNO Robot with Dual DC Motors and L298N Driver

Circuit Documentation

Summary

This circuit is designed to control two DC motors using an Arduino UNO microcontroller and an L298N DC motor driver. It includes a Bluetooth HC-06 module for wireless communication, allowing the motors to be controlled remotely via Bluetooth commands. The circuit is powered by a 9V battery connected through a rocker switch and also includes a 4 x AAA battery mount connected to a power jack for an alternative power source.

Component List

Arduino UNO

Rocker Switch

DC Motor (x2)

Bluetooth HC-06

4 x AAA Battery Mount

9V Battery

L298N DC Motor Driver

Power Jack

Wiring Details

Arduino UNO

Rocker Switch

DC Motor #1

DC Motor #2

Bluetooth HC-06

4 x AAA Battery Mount

9V Battery

L298N DC Motor Driver

Power Jack

Documented Code

#include <SoftwareSerial.h>
SoftwareSerial BT(4,2); // Bluetooth communication on pins D4 (TX) and D2 (RX)

// Motor 1
int ENA = 10; // Enable pin for motor A
int IN1 = 9;  // Input 1 for motor A
int IN2 = 8;  // Input 2 for motor A

// Motor 2
int ENB = 5;  // Enable pin for motor B
int IN3 = 7;  // Input 3 for motor B
int IN4 = 6;  // Input 4 for motor B

void setup() {
  Serial.begin(9600); // Start serial communication at 9600 baud rate
  BT.begin(9600);     // Start Bluetooth communication at 9600 baud rate

  // Set motor control pins as outputs
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
}

void loop() {
  if (BT.available()) { // Check if there is Bluetooth data available
    char data = BT.read(); // Read the incoming byte

    switch(data) {
      case 'a': // Command to move forward
        Forward();
        break;
      case 'r': // Command to move backward
        Backward();
        break;
      case 'd': // Command to turn right
        Right();
        break;
      case 'g': // Command to turn left
        Left();
        break;
      case 'p': // Command to stop
        Stop();
        break;
    }
  }
}

void Forward() {
  // Set motor A direction and speed
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  analogWrite(ENA, 255); // Full speed
  // Set motor B direction and speed
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  analogWrite(ENB, 255); // Full speed
}

void Right() {
  // Set motor A to reverse direction at a slower speed
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  analogWrite(ENA, 100); // Reduced speed
  // Set motor B to forward direction at a slower speed
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  analogWrite(ENB, 100); // Reduced speed
}

void Left() {
  // Set motor A to forward direction at a slower speed
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  analogWrite(ENA, 100); // Reduced speed
  // Set motor B to reverse direction at a slower speed
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  analogWrite(ENB, 100); // Reduced speed
}

void Backward() {
  // Set motor A to reverse direction and speed
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  analogWrite(ENA, 255); // Full speed
  // Set motor B to reverse direction and speed
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  analogWrite(ENB, 255); // Full speed
}

void Stop() {
  // Stop motor A
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  analogWrite(ENA, 0); // No speed
  // Stop motor B
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  analogWrite(ENB, 0); // No speed
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It sets up a SoftwareSerial connection for Bluetooth communication and defines functions to control the direction and speed of two DC motors using the L298N motor driver. The Arduino listens for Bluetooth commands to control the motors: 'a' for forward, 'r' for backward, 'd' for right, 'g' for left, and 'p' for stop.