Building upon the mechanical chassis assembled on Day 2, Day 3 transforms the robot car into an interactive teleoperated vehicle:
F (Forward), B (Back), L (Left Spin), R (Right Spin), S (Stop), and dynamic speed tiers 1 to 5.SoftwareSerial on Pins 2 & 3 to drive wirelessly using Android/iOS joystick apps with fail-safe auto-stop timeout protection.| Module / Component | Module Pin | Arduino Pin | Wiring Function & Notes |
|---|---|---|---|
| L298N Speed A | ENA | Pin 5 (PWM) | Left Motor speed control via analogWrite; remove jumper cap |
| L298N Direction A | IN1, IN2 | Pin 6, Pin 7 | Left Motor direction logic gates |
| L298N Direction B | IN3, IN4 | Pin 8, Pin 9 | Right Motor direction logic gates |
| L298N Speed B | ENB | Pin 10 (PWM) | Right Motor speed control via analogWrite; remove jumper cap |
| HC-05 Bluetooth | VCC | 5V Header | Power supply for Bluetooth module |
| HC-05 Bluetooth | GND | GND Header | Common Ground reference |
| HC-05 Bluetooth | TXD | Pin 2 (RX) | SoftwareSerial RX (receives serial from phone) |
| HC-05 Bluetooth | RXD | Pin 3 (TX) | SoftwareSerial TX via 1k/2k voltage divider (3.3V logic protection) |
| Active Buzzer | Positive (+) | Pin 4 | Horn / Alert sounder when 'H' command is received |
| Battery Ground | Negative (−) | L298N GND & Uno GND | MANDATORY: Common Ground Bridge Junction! |
Always connect the HC-05 module to dedicated software serial pins (Pins 2 & 3). If you connect Bluetooth to Hardware Serial (Pins 0 & 1), the Bluetooth module will fight with your computer's USB programmer, blocking code uploads with avrdude: stk500_recv(): programmer is not responding errors.
The HC-05 Bluetooth transceiver chip runs on 3.3V internal logic. While it can safely output 3.3V to Arduino Pin 2 (RX), sending a full 5V signal from Arduino Pin 3 (TX) directly into the HC-05 RX pin can overheat or damage it over time. Always insert a simple resistor voltage divider (1kΩ in series, 2kΩ to GND) to drop the 5V signal safely down to ~3.3V.
Wireless connections can drop unexpectedly if the car drives out of range. Never program a car to move indefinitely! Our firmware includes an automatic safety watchdog: if no command is received for 3 seconds while driving, the car automatically brakes to an immediate stop.
Notice the dual baud rates in our setup: Serial.begin(115200) connects to the high-speed USB PC monitor, while BT.begin(9600) connects to the factory-default HC-05 communication channel. Never mix them up!
When pairing your smartphone with the HC-05 module in Bluetooth Settings, the prompt will ask for a PIN. The universal default passcode is either 1234 or 0000. Once paired, the red LED on the HC-05 will slow down from rapid flashing to a steady double-blink.
/*
* Connect Robo - PC Serial Car Controller (V2)
* Baud Rate: 115200 bps | Target: Arduino Uno
* Controls: 'F'=Forward, 'B'=Back, 'L'=Spin Left, 'R'=Spin Right, 'S'=Stop, 'H'=Horn
* Speed Tiers: '1' (130) to '5' (255) | 3-Second Inactivity Watchdog
*/
const int ENA = 5, IN1 = 6, IN2 = 7, IN3 = 8, IN4 = 9, ENB = 10, BUZZER = 4;
int currentSpeed = 190, speedTier = 3;
unsigned long lastCmdTime = 0;
bool isMoving = false;
void setup() {
Serial.begin(115200);
pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); pinMode(ENB, OUTPUT);
pinMode(BUZZER, OUTPUT);
stopMotors();
Serial.println(F("=================================================="));
Serial.println(F("🤖 Connect Robo PC Serial Car Controller Ready!"));
Serial.println(F("Commands: F (Fwd), B (Back), L (Left), R (Right), S (Stop)"));
Serial.println(F("Speed Tiers: '1' (Slow) to '5' (Max) | H (Horn) | ? (Telemetry)"));
Serial.println(F("=================================================="));
}
void loop() {
if (Serial.available()) {
char cmd = Serial.read();
if (cmd != '\r' && cmd != '\n' && cmd != ' ') {
processCommand(cmd);
lastCmdTime = millis();
}
}
// Safety watchdog: auto-stop if no key pressed within 3 seconds
if (isMoving && (millis() - lastCmdTime > 3000)) {
stopMotors();
Serial.println(F("[SAFETY] Auto-stop triggered (3s inactivity)"));
}
}
void processCommand(char cmd) {
switch (cmd) {
case 'F': case 'f': moveForward(); break;
case 'B': case 'b': moveBackward(); break;
case 'L': case 'l': turnLeft(); break;
case 'R': case 'r': turnRight(); break;
case 'S': case 's': stopMotors(); Serial.println(F("[CAR] STOPPED")); break;
case '1': setSpeed(1, 130); break;
case '2': setSpeed(2, 160); break;
case '3': setSpeed(3, 190); break;
case '4': setSpeed(4, 225); break;
case '5': setSpeed(5, 255); break;
case 'H': case 'h': honk(); break;
case '?': printTelemetry(); break;
}
}
void moveForward() {
analogWrite(ENA, currentSpeed); analogWrite(ENB, currentSpeed);
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
isMoving = true;
Serial.print(F("[CAR] FORWARD @ PWM ")); Serial.println(currentSpeed);
}
void moveBackward() {
analogWrite(ENA, currentSpeed); analogWrite(ENB, currentSpeed);
digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
isMoving = true;
Serial.print(F("[CAR] BACKWARD @ PWM ")); Serial.println(currentSpeed);
}
void turnLeft() {
analogWrite(ENA, currentSpeed); analogWrite(ENB, currentSpeed);
digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
isMoving = true;
Serial.println(F("[CAR] SPIN LEFT"));
}
void turnRight() {
analogWrite(ENA, currentSpeed); analogWrite(ENB, currentSpeed);
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
isMoving = true;
Serial.println(F("[CAR] SPIN RIGHT"));
}
void stopMotors() {
digitalWrite(IN1, LOW); digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); digitalWrite(IN4, LOW);
analogWrite(ENA, 0); analogWrite(ENB, 0);
isMoving = false;
}
void setSpeed(int tier, int pwm) {
speedTier = tier; currentSpeed = pwm;
if (isMoving) { analogWrite(ENA, currentSpeed); analogWrite(ENB, currentSpeed); }
Serial.print(F("[SPEED] Tier ")); Serial.print(tier);
Serial.print(F(" -> PWM ")); Serial.println(pwm);
}
void honk() {
digitalWrite(BUZZER, HIGH); delay(150); digitalWrite(BUZZER, LOW);
}
void printTelemetry() {
Serial.print(F("State: ")); Serial.println(isMoving ? F("MOVING") : F("STOPPED"));
Serial.print(F("Speed Tier: ")); Serial.print(speedTier);
Serial.print(F(" (PWM: ")); Serial.print(currentSpeed); Serial.println(F("/255)"));
}
/*
* Connect Robo - Bluetooth Smartphone Controlled Smart Car
* Target MCU: Arduino Uno | SoftwareSerial: RX=2, TX=3 | Bluetooth: 9600 bps
* PC Serial Monitor: 115200 bps | Fail-Safe Watchdog Timer: 3.5 Seconds
*/
#include <SoftwareSerial.h>
SoftwareSerial BT(2, 3); // Arduino RX=Pin 2, TX=Pin 3
const int ENA = 5, IN1 = 6, IN2 = 7, IN3 = 8, IN4 = 9, ENB = 10, BUZZER = 4;
int motorSpeed = 200;
unsigned long lastPacket = 0;
bool isMoving = false;
void setup() {
Serial.begin(115200); // PC Console Monitor
BT.begin(9600); // HC-05 Default Bluetooth Speed
pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); pinMode(ENB, OUTPUT);
pinMode(BUZZER, OUTPUT);
stopMotors();
Serial.println(F("=================================================="));
Serial.println(F("📱 Connect Robo Bluetooth RC Car Initialized!"));
Serial.println(F("Listening for smartphone app commands on SoftwareSerial (9600)..."));
Serial.println(F("=================================================="));
}
void loop() {
// Read incoming Bluetooth packets from smartphone
if (BT.available()) {
char cmd = BT.read();
if (cmd != '\r' && cmd != '\n' && cmd != ' ') {
executeBluetoothCommand(cmd);
lastPacket = millis();
}
}
// Also accept commands from PC serial monitor for debugging
if (Serial.available()) {
char cmd = Serial.read();
if (cmd != '\r' && cmd != '\n') {
executeBluetoothCommand(cmd);
lastPacket = millis();
}
}
// Watchdog: Stop motors if Bluetooth signal drops for > 3.5 seconds
if (isMoving && (millis() - lastPacket > 3500)) {
stopMotors();
Serial.println(F("[SAFETY] BT signal timeout - auto-stopped"));
}
}
void executeBluetoothCommand(char cmd) {
switch (cmd) {
case 'F': case 'f':
moveForward();
break;
case 'B': case 'b':
moveBackward();
break;
case 'L': case 'l':
spinLeft();
break;
case 'R': case 'r':
spinRight();
break;
case 'S': case 's':
stopMotors();
Serial.println(F("[BT] STOP"));
break;
case '1': setSpeed(130); break;
case '2': setSpeed(165); break;
case '3': setSpeed(200); break;
case '4': setSpeed(230); break;
case '5': setSpeed(255); break;
case 'H': case 'h':
digitalWrite(BUZZER, HIGH);
delay(120);
digitalWrite(BUZZER, LOW);
break;
default:
break;
}
}
void moveForward() {
analogWrite(ENA, motorSpeed); analogWrite(ENB, motorSpeed);
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
isMoving = true;
Serial.print(F("[BT] FORWARD @ ")); Serial.println(motorSpeed);
}
void moveBackward() {
analogWrite(ENA, motorSpeed); analogWrite(ENB, motorSpeed);
digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
isMoving = true;
Serial.print(F("[BT] BACKWARD @ ")); Serial.println(motorSpeed);
}
void spinLeft() {
analogWrite(ENA, motorSpeed); analogWrite(ENB, motorSpeed);
digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
isMoving = true;
Serial.println(F("[BT] SPIN LEFT"));
}
void spinRight() {
analogWrite(ENA, motorSpeed); analogWrite(ENB, motorSpeed);
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
isMoving = true;
Serial.println(F("[BT] SPIN RIGHT"));
}
void stopMotors() {
digitalWrite(IN1, LOW); digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); digitalWrite(IN4, LOW);
analogWrite(ENA, 0); analogWrite(ENB, 0);
isMoving = false;
}
void setSpeed(int pwm) {
motorSpeed = pwm;
if (isMoving) {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
}
Serial.print(F("[BT] Speed set to ")); Serial.println(motorSpeed);
}
| Issue Observed | Underlying Cause | Instant Classroom Remedy |
|---|---|---|
| Bluetooth does not appear in phone search | HC-05 is unpowered or has loose jumper wires. | Check VCC to 5V and GND to GND. Red LED on HC-05 must be blinking rapidly. |
| Phone connects but car does not move | TX/RX lines are connected backwards. | Remember crossover: HC-05 TXD goes to Arduino Pin 2 (RX)! |
| Code will not upload to Arduino Uno | Bluetooth is plugged into hardware Pins 0/1. | Ensure HC-05 is plugged into Pins 2 & 3, not Pins 0 & 1! |
| Car stutters or resets when driving wirelessly | Battery voltage drop under motor load or missing common ground. | Verify 18650 cells are charged, and check common ground connection to L298N GND. |
| Serial monitor shows garbled strange characters | Baud rate mismatch in serial monitor window. | Set Arduino Serial Monitor to 115200 Baud (bottom right corner). |