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

Arduino UNO Bluetooth-Controlled Car with L298N Motor Driver

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

Circuit Documentation

Summary

This document provides a detailed overview of a Bluetooth-controlled car circuit. The circuit uses an Arduino UNO microcontroller to control a car via an L298N motor driver and an HC-05 Bluetooth module. The car can move forward, backward, turn left, and turn right based on commands received via Bluetooth. Additionally, it can control two LEDs for signaling purposes.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. L298N DC Motor Driver

    • Description: A dual H-Bridge motor driver module that allows control of the speed and direction of 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: A Bluetooth module that enables wireless communication between the Arduino and other Bluetooth-enabled devices.
    • Pins: Key, VCC, GND, TXD, RXD, State
  4. 5V Battery

    • Description: A power source providing 5V DC.
    • Pins: +, -

Wiring Details

Arduino UNO

L298N DC Motor Driver

HC-05 Bluetooth Module

5V Battery

Code Documentation

/*
 * Arduino Sketch for Bluetooth Controlled Car
 *
 * This code allows an Arduino UNO to control a car using an L298N motor driver
 * and an HC-05 Bluetooth module. The car can move forward, backward, turn left,
 * and turn right based on commands received via Bluetooth. Additionally, it can
 * control two LEDs for signaling purposes.
 */

char t = '\0';  // Initialize with a default value

void setup() {
  // Motor pins
  pinMode(13, OUTPUT);   // Left motor forward
  pinMode(12, OUTPUT);   // Left motor reverse
  pinMode(11, OUTPUT);   // Right motor forward
  pinMode(10, OUTPUT);   // Right motor reverse

  // LED pins
  pinMode(9, OUTPUT);    // Main LED
  pinMode(8, OUTPUT);    // Back LED

  // Start serial communication at 9600 baud rate
  Serial.begin(9600);
}

void loop() {
  // Check if data is available from the HC-05 Bluetooth module
  if (Serial.available()) {
    t = Serial.read();  // Read the incoming character

    // Execute command based on the received character
    switch (t) {
      case 'F':  // Move forward
        digitalWrite(13, HIGH);  
        digitalWrite(11, HIGH);  
        digitalWrite(12, LOW);   
        digitalWrite(10, LOW);   
        break;

      case 'B':  // Move backward
        digitalWrite(13, LOW);   
        digitalWrite(11, LOW);   
        digitalWrite(12, HIGH);  
        digitalWrite(10, HIGH);  
        break;

      case 'L':  // Turn left
        digitalWrite(13, LOW);   
        digitalWrite(12, HIGH);  
        digitalWrite(11, HIGH);  
        digitalWrite(10, LOW);   
        break;

      case 'R':  // Turn right
        digitalWrite(13, HIGH);  
        digitalWrite(12, LOW);   
        digitalWrite(11, LOW);   
        digitalWrite(10, HIGH);  
        break;

      case 'W':  // Turn main LED on
        digitalWrite(9, HIGH);   
        break;

      case 'w':  // Turn main LED off
        digitalWrite(9, LOW);    
        break;

      case 'M':  // Turn back LED on
        digitalWrite(8, HIGH);   
        break;

      case 'm':  // Turn back LED off
        digitalWrite(8, LOW);    
        break;

      case 'S':  // Stop all motors and LEDs
        digitalWrite(13, LOW);   
        digitalWrite(12, LOW);   
        digitalWrite(11, LOW);   
        digitalWrite(10, LOW);   
        digitalWrite(9, LOW);    
        digitalWrite(8, LOW);    
        break;

      default:
        // Handle any unrecognized command if needed
        break;
    }
  }
}

This code initializes the necessary pins for motor and LED control, sets up serial communication, and continuously checks for incoming Bluetooth commands to control the car's movements and LED states.