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

Arduino UNO Bluetooth-Controlled Robotic Car with Rotary Encoder and Motor Driver

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

Circuit Documentation

Summary

This circuit is designed to control a set of DC motors and a brushless motor using an Arduino UNO. The circuit includes a rotary encoder for position feedback and an HC-05 Bluetooth module for wireless communication. The L298N motor driver is used to control the DC motors, while an Electronic Speed Controller (ESC) is used to control the brushless motor. The circuit is powered by a 12V battery.

Component List

  1. Arduino UNO

    • Description: 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: Dual H-Bridge motor driver.
    • 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: STATE, RXD, TXD, GND, VCC, EN
  4. DC Mini Metal Gear Motor

    • Description: Small DC motor with metal gears.
    • Pins: IN1, IN2
  5. Brushless Motor

    • Description: Motor with three-phase windings.
    • Pins: L1, L2, L3
  6. Rotary Encoder

    • Description: Device for measuring rotational position.
    • Pins: clk, dt, sw, gnd, +
  7. Electronic Speed Controller (ESC)

    • Description: Device for controlling brushless motors.
    • Pins: Battery VCC, Battery GND, Signal, 5v out, GND out, M1, M2, M3
  8. 12V Battery (Small Size)

    • Description: Power source for the circuit.
    • Pins: VCC, GND

Wiring Details

Arduino UNO

L298N DC Motor Driver

HC-05 Bluetooth Module

DC Mini Metal Gear Motor

Brushless Motor

Rotary Encoder

Electronic Speed Controller (ESC)

12V Battery (Small Size)

Documented Code

// Motor control pins
const int ENA = 5; // Speed control for Left Motor Pair
const int ENB = 6; // Speed control for Right Motor Pair
const int IN1 = 7; // Left Motor Forward
const int IN2 = 8; // Left Motor Backward
const int IN3 = 9; // Right Motor Forward
const int IN4 = 10; // Right Motor Backward

// ESC control pin
const int ESC_PIN = 11;

// Rotary Encoder pins
const int CLK = A0;
const int DT = A1;
const int SW = A2;

int encoderPos = 0;
int lastCLK = LOW;

// Bluetooth input
char command;

void setup() {
  // Motor driver pins
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  // Rotary Encoder
  pinMode(CLK, INPUT);
  pinMode(DT, INPUT);
  pinMode(SW, INPUT_PULLUP);
  lastCLK = digitalRead(CLK);

  // ESC setup
  pinMode(ESC_PIN, OUTPUT);
  analogWrite(ESC_PIN, 0); // Initialize ESC at 0 speed

  // Bluetooth
  Serial.begin(9600);
}

void loop() {
  // Read Bluetooth commands
  if (Serial.available() > 0) {
    command = Serial.read();
    handleCommand(command);
  }

  // Update Rotary Encoder position
  int currentCLK = digitalRead(CLK);
  if (currentCLK != lastCLK && currentCLK == HIGH) {
    if (digitalRead(DT) != currentCLK) {
      encoderPos++;
    } else {
      encoderPos--;
    }
  }
  lastCLK = currentCLK;

  delay(10); // Small delay for stability
}

// Command handler
void handleCommand(char cmd) {
  switch (cmd) {
    case 'F': //