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

Arduino and Bluetooth Controlled DC Motor Robot with L298N Driver

View and Edit Project In Cirkit DesignerImage of Arduino and Bluetooth Controlled DC Motor Robot with L298N Driver

Circuit Documentation

Summary

This circuit is designed to control four DC motors using an Arduino 101 microcontroller, an L298N DC motor driver, and an HC-05 Bluetooth module. The motors are powered by a combination of 3.7V batteries and a 9V battery. The Bluetooth module allows for wireless control of the motors via commands sent from a paired device.

Component List

  1. Arduino 101

    • Description: Microcontroller board based on the Intel Curie module.
    • Pins: A5/SCL, A4/SDA, AREF, GND, D13/SCK, D12/MISO, D11 PWM/MOSI, D10 PWM/SS, D9 PWM, D8, D7, D6 PWM, D5 PWM, D4, D3 PWM, D2, D1/TX, D0/RX, AIN, ioref, RESET, 3V3, 5V, VIN, A0, A1, A2, A3, ICSP MISO, ICSP SCK, ICSP MOSI
  2. L298N DC Motor Driver

    • Description: Dual H-Bridge motor driver for controlling two 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
  3. HC-05 Bluetooth Module

    • Description: Bluetooth module for wireless communication.
    • Pins: Key, VCC, GND, TXD, RXD, State
  4. DC Motor

    • Description: Standard DC motor.
    • Pins: pin 1, pin 2
  5. 9V Battery

    • Description: Standard 9V battery for powering the Arduino.
    • Pins: -, +
  6. 3.7V Battery

    • Description: Standard 3.7V battery for powering the motor driver.
    • Pins: +, -

Wiring Details

Arduino 101

L298N DC Motor Driver

HC-05 Bluetooth Module

DC Motors

9V Battery

3.7V Batteries

Documented Code

#include <SoftwareSerial.h>

// Pin definitions for L298N motor driver
const int ENA = 9;  // PWM pin for motor A
const int IN1 = 8;  // Control pin 1 for motor A
const int IN2 = 7;  // Control pin 2 for motor A
const int ENB = 10; // PWM pin for motor B
const int IN3 = 6;  // Control pin 1 for motor B
const int IN4 = 5;  // Control pin 2 for motor B

// Bluetooth module pins
const int BT_RX = 2; // Bluetooth module TX to Arduino RX
const int BT_TX = 3; // Bluetooth module RX to Arduino TX

SoftwareSerial bluetooth(BT_RX, BT_TX);

void setup() {
  // Initialize motor control pins as outputs
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  // Initialize serial communication for Bluetooth
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    char command = Serial.read();

    switch (command) {
      case 'F': // Move forward
        moveForward();
        break;
      case 'B': // Move backward
        moveBackward();
        break;
      case 'L': // Turn left
        turnLeft();
        break;
      case 'R': // Turn right
        turnRight();
        break;
      case 'S': // Stop
        stopMotors();
        break;
      default:
        // Unknown command
        break;
    }
  }
}

void moveForward() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  analogWrite(ENA, 255); // Full speed

  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  analogWrite(ENB, 255); // Full speed
}

void moveBackward() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  analogWrite(ENA, 255); // Full speed

  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  analogWrite(ENB, 255); // Full speed
}

void turnLeft() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  analogWrite(ENA, 255); // Full speed

  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  analogWrite(ENB, 255); // Full speed
}

void turnRight() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  analogWrite(ENA, 255); // Full speed

  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  analogWrite(EN