Arduino UNO Bluetooth-Controlled Robotic Car with Rotary Encoder and Motor Driver
View and Edit Project In Cirkit Designer
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
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
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
HC-05 Bluetooth Module
- Description: Bluetooth module for wireless communication.
- Pins: STATE, RXD, TXD, GND, VCC, EN
DC Mini Metal Gear Motor
- Description: Small DC motor with metal gears.
- Pins: IN1, IN2
Brushless Motor
- Description: Motor with three-phase windings.
- Pins: L1, L2, L3
Rotary Encoder
- Description: Device for measuring rotational position.
- Pins: clk, dt, sw, gnd, +
Electronic Speed Controller (ESC)
- Description: Device for controlling brushless motors.
- Pins: Battery VCC, Battery GND, Signal, 5v out, GND out, M1, M2, M3
12V Battery (Small Size)
- Description: Power source for the circuit.
- Pins: VCC, GND
Wiring Details
Arduino UNO
- GND: Connected to GND of Rotary Encoder, 12V Battery, ESC, HC-05, and L298N DC Motor Driver.
- Vin: Connected to + of Rotary Encoder and VCC of 12V Battery.
- A0: Connected to clk of Rotary Encoder.
- A1: Connected to dt of Rotary Encoder.
- A2: Connected to sw of Rotary Encoder.
- D11: Connected to Signal of ESC.
- D10: Connected to IN4 of L298N DC Motor Driver.
- D9: Connected to IN3 of L298N DC Motor Driver.
- D8: Connected to IN2 of L298N DC Motor Driver.
- D7: Connected to IN1 of L298N DC Motor Driver.
- D6: Connected to ENB of L298N DC Motor Driver.
- D5: Connected to ENA of L298N DC Motor Driver.
- D1: Connected to RXD of HC-05.
- D0: Connected to TXD of HC-05.
L298N DC Motor Driver
- GND: Connected to GND of Arduino UNO, 12V Battery, ESC, HC-05, and Rotary Encoder.
- 5V: Connected to + of Rotary Encoder, Vin of Arduino UNO, VCC of 12V Battery, 5v out of ESC, and VCC of HC-05.
- IN1: Connected to D7 of Arduino UNO.
- IN2: Connected to D8 of Arduino UNO.
- IN3: Connected to D9 of Arduino UNO.
- IN4: Connected to D10 of Arduino UNO.
- ENA: Connected to D5 of Arduino UNO.
- ENB: Connected to D6 of Arduino UNO.
- OUT1: Connected to IN1 of two DC Mini Metal Gear Motors.
- OUT2: Connected to IN2 of two DC Mini Metal Gear Motors.
- OUT3: Connected to IN1 of two DC Mini Metal Gear Motors.
- OUT4: Connected to IN2 of two DC Mini Metal Gear Motors.
HC-05 Bluetooth Module
- GND: Connected to GND of Arduino UNO, 12V Battery, ESC, L298N DC Motor Driver, and Rotary Encoder.
- VCC: Connected to + of Rotary Encoder, Vin of Arduino UNO, VCC of 12V Battery, and 5v out of ESC.
- RXD: Connected to D1 of Arduino UNO.
- TXD: Connected to D0 of Arduino UNO.
DC Mini Metal Gear Motor
- IN1: Connected to OUT1 of L298N DC Motor Driver.
- IN2: Connected to OUT2 of L298N DC Motor Driver.
- IN1: Connected to OUT3 of L298N DC Motor Driver.
- IN2: Connected to OUT4 of L298N DC Motor Driver.
Brushless Motor
- L1: Connected to M1 of ESC.
- L2: Connected to M2 of ESC.
- L3: Connected to M3 of ESC.
Rotary Encoder
- gnd: Connected to GND of Arduino UNO, 12V Battery, ESC, HC-05, and L298N DC Motor Driver.
- +: Connected to Vin of Arduino UNO and VCC of 12V Battery.
- clk: Connected to A0 of Arduino UNO.
- dt: Connected to A1 of Arduino UNO.
- sw: Connected to A2 of Arduino UNO.
Electronic Speed Controller (ESC)
- Battery VCC: Connected to VCC of 12V Battery.
- Battery GND: Connected to GND of 12V Battery.
- Signal: Connected to D11 of Arduino UNO.
- 5v out: Connected to + of Rotary Encoder, Vin of Arduino UNO, VCC of 12V Battery, and VCC of HC-05.
- GND out: Connected to GND of Arduino UNO, 12V Battery, HC-05, L298N DC Motor Driver, and Rotary Encoder.
- M1: Connected to L1 of Brushless Motor.
- M2: Connected to L2 of Brushless Motor.
- M3: Connected to L3 of Brushless Motor.
12V Battery (Small Size)
- VCC: Connected to + of Rotary Encoder, Vin of Arduino UNO, 5v out of ESC, and VCC of HC-05.
- GND: Connected to GND of Arduino UNO, ESC, HC-05, L298N DC Motor Driver, and Rotary Encoder.
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': //