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

Arduino UNO Bluetooth-Controlled Robot with L298N Motor Driver

Image of Arduino UNO Bluetooth-Controlled Robot with L298N Motor Driver

Circuit Documentation

Summary

This circuit is designed to control a robotic vehicle with two DC gearmotors for movement, which are driven by an L298N motor driver module. The Arduino UNO serves as the central microcontroller, interfacing with an HC-06 Bluetooth module for wireless communication. The system is powered by two 18650 Li-ion batteries, and a PWM motor speed controller is used to regulate the speed of additional DC gearmotors. A rocker switch is included to control the power supply to the motor driver.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P.
  • It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.

Gearmotor DC Wheels (Left and Right)

  • DC gearmotors used for the left and right wheels of the robotic vehicle.
  • Each motor has two connection pins.

PWM Motor Speed Controller

  • A device that controls the speed of a DC motor by adjusting the pulse width of the voltage sent to the motor.

18650 Li-ion Battery x 2

  • Two rechargeable lithium-ion batteries providing the power source for the circuit.

Gearmotor DC / Motorreductor

  • Additional DC gearmotors that can be used for other functions in the robotic vehicle.

L298N DC Motor Driver

  • A high-power motor driver module that can drive up to two DC motors.
  • It has inputs for motor control signals and power supply connections.

HC-06

  • A Bluetooth module that allows for wireless communication with the Arduino UNO.

Rocker Switch

  • A switch used to control the power supply to the motor driver.

Wiring Details

Arduino UNO

  • 5V connected to HC-06 VCC.
  • GND connected to 18650 Li-ion Battery -, PWM motor speed controller Power-, and L298N motor driver GND.
  • Vin connected to L298N motor driver 5V.
  • D13 connected to L298N motor driver IN1.
  • D12 connected to L298N motor driver IN2.
  • D11 connected to L298N motor driver IN3.
  • D10 connected to L298N motor driver IN4.
  • D6 connected to L298N motor driver ENA.
  • D5 connected to L298N motor driver ENB.
  • D1 connected to HC-06 RXD.
  • D0 connected to HC-06 TXD.

Gearmotor DC Wheels (Left and Right)

  • Left PIN1 connected to L298N motor driver OUT1.
  • Left PIN2 connected to L298N motor driver OUT2.
  • Right PIN1 connected to L298N motor driver OUT4.
  • Right PIN2 connected to L298N motor driver OUT3.

PWM Motor Speed Controller

  • Motor+ connected to both Gearmotor DC / Motorreductor Pin1.
  • Motor- connected to both Gearmotor DC / Motorreductor Pin2.
  • Power+ connected to Rocker Switch 1 and 18650 Li-ion Battery +.

L298N DC Motor Driver

  • 12V connected to Rocker Switch 2.

HC-06

  • GND connected to Arduino UNO GND.

Rocker Switch

  • 1 connected to 18650 Li-ion Battery + and PWM motor speed controller Power+.
  • 2 connected to L298N motor driver 12V.

Documented Code

int ENA = 6;
int IN1 = 13;
int IN2 = 12;
int ENB = 5;
int IN3 = 11;
int IN4 = 10;
int speedValue = 0;

void setup() {
  Serial.begin(9600);   // Start Bluetooth serial communication using default RX/TX

  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
}

void loop() {
  if (Serial.available()) {
    char command = Serial.read();  // Read the command from Bluetooth

    Serial.print("Received command: ");
    Serial.println(command);

    // Movement Commands
    if (command == 'F') {
      // Move Forward
      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      analogWrite(ENA, speedValue); // Control speed
      analogWrite(ENB, speedValue);

    } else if (command == 'B') {
      // Move Backward
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      analogWrite(ENA, speedValue);
      analogWrite(ENB, speedValue);

    } else if (command == 'L') {
      // Turn Left
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);
      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      analogWrite(ENA, speedValue);
      analogWrite(ENB, speedValue);

    } else if (command == 'R') {
      // Turn Right
      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      analogWrite(ENA, speedValue);
      analogWrite(ENB, speedValue);

    } else if (command == 'S') {
      // Stop
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, LOW);
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, LOW);

    } 
    // Speed control commands (0 to 9 for speed levels 0 to 100)
    else if (command >= '0' && command <= '9') {
      speedValue = map(command - '0', 0, 9, 0, 255);
      Serial.print("Speed set to: ");
      Serial.println(speedValue);
    }
  }
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It sets up the necessary pins for motor control and listens for Bluetooth commands to control the movement and speed of the motors. The commands 'F', 'B', 'L', 'R', and 'S' correspond to forward, backward, left, right, and stop movements, respectively. Speed is adjusted with numeric commands '0' to '9'.