Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Bluetooth-Controlled Arduino Robot with L298N Motor Driver

Image of Bluetooth-Controlled Arduino Robot with L298N Motor Driver

Circuit Documentation

Summary

The circuit in question is designed to control a four-wheeled vehicle using an Arduino UNO microcontroller and an L298N DC motor driver. The vehicle is equipped with four motors and wheels, and it receives commands via a Bluetooth module (HC-05) to move forward, backward, turn left, and turn right. The Arduino UNO is programmed to interpret the Bluetooth commands and drive the motors accordingly. The power for the motor driver is supplied by a 12V battery, which also powers the Arduino through a voltage regulator.

Component List

L298N DC Motor Driver

  • Description: A motor driver module capable of driving up to four 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.

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P, widely used for building digital devices and interactive objects.
  • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13.

HC-05 Bluetooth Module

  • Description: A Bluetooth module for wireless communication.
  • Pins: EN, VCC, GND, TXD, RXD, STATE.

12V Battery

  • Description: A power source for the motor driver and indirectly for the Arduino UNO.
  • Pins: + (positive terminal), - (negative terminal).

Motors and Wheels (4x)

  • Description: DC motors connected to wheels, providing mobility for the vehicle.
  • Pins: VCC, GND.

Wiring Details

L298N DC Motor Driver

  • 12V connected to the positive terminal of the 12V battery.
  • GND connected to the negative terminal of the 12V battery and Arduino UNO GND.
  • 5V connected to Arduino UNO Vin.
  • OUT1, OUT2 connected to the first pair of motors and wheels.
  • OUT3, OUT4 connected to the second pair of motors and wheels.
  • ENA, ENB connected to Arduino UNO D6 and D5 for enabling motor control.
  • IN1, IN2, IN3, IN4 connected to Arduino UNO D4, D7, D8, and D9 for motor direction control.

Arduino UNO

  • Vin connected to L298N DC motor driver 5V.
  • GND connected to L298N DC motor driver GND and HC-05 GND.
  • 5V connected to HC-05 VCC.
  • D0-D9 various connections to L298N DC motor driver and HC-05 for control signals.

HC-05 Bluetooth Module

  • VCC connected to Arduino UNO 5V.
  • GND connected to Arduino UNO GND.
  • TXD connected to Arduino UNO D0.
  • RXD connected to Arduino UNO D1.

Motors and Wheels

  • VCC connected to L298N DC motor driver OUT1, OUT3 for two motors and OUT2, OUT4 for the other two motors.
  • GND connected to L298N DC motor driver OUT2, OUT4 for two motors and OUT1, OUT3 for the other two motors.

Documented Code

#include <AFMotor.h>

// Initialize motors
AF_DCMotor motor1(1, MOTOR12_1KHZ); 
AF_DCMotor motor2(2, MOTOR12_1KHZ); 
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

char command; 

void setup() 
{       
  Serial.begin(9600);  // Set the baud rate for Bluetooth module communication.
}

void loop(){
  if(Serial.available() > 0){ 
    command = Serial.read(); 
    Stop(); // Initialize with motors stopped
    // Execute command received via Bluetooth
    switch(command){
    case 'F':  
      forward();
      break;
    case 'B':  
       back();
      break;
    case 'L':  
      left();
      break;
    case 'R':
      right();
      break;
    }
  } 
}

void forward()
{
  // Set motors to move forward at maximum speed
  motor1.setSpeed(255);
  motor1.run(FORWARD);
  motor2.setSpeed(255);
  motor2.run(FORWARD);
  motor3.setSpeed(255);
  motor3.run(FORWARD);
  motor4.setSpeed(255);
  motor4.run(FORWARD);
}

void back()
{
  // Set motors to move backward at maximum speed
  motor1.setSpeed(255);
  motor1.run(BACKWARD);
  motor2.setSpeed(255);
  motor2.run(BACKWARD);
  motor3.setSpeed(255);
  motor3.run(BACKWARD);
  motor4.setSpeed(255);
  motor4.run(BACKWARD);
}

void left()
{
  // Set motors to turn left
  motor1.setSpeed(255);
  motor1.run(BACKWARD);
  motor2.setSpeed(255);
  motor2.run(BACKWARD);
  motor3.setSpeed(255);
  motor3.run(FORWARD);
  motor4.setSpeed(255);
  motor4.run(FORWARD);
}

void right()
{
  // Set motors to turn right
  motor1.setSpeed(255);
  motor1.run(FORWARD);
  motor2.setSpeed(255);
  motor2.run(FORWARD);
  motor3.setSpeed(255);
  motor3.run(BACKWARD);
  motor4.setSpeed(255);
  motor4.run(BACKWARD);
} 

void Stop()
{
  // Stop all motors
  motor1.setSpeed(0);
  motor1.run(RELEASE);
  motor2.setSpeed(0);
  motor2.run(RELEASE);
  motor3.setSpeed(0);
  motor3.run(RELEASE);
  motor4.setSpeed(0);
  motor4.run(RELEASE);
}

This code is designed to be uploaded to an Arduino UNO microcontroller. It includes a setup function to initialize serial communication for the HC-05 Bluetooth module and a loop function that listens for incoming commands to control the motors. The commands 'F', 'B', 'L', and 'R' correspond to forward, backward, left, and right movements, respectively. The motor control functions set the speed and direction of the motors to achieve the desired movement.