Satpuda STEM Lab · Curriculum Day 3 Dossier · Sunday, 22 November 2026

PC Serial & Bluetooth Smartphone Robot Car Driving

Connect keyboard serial telemetry and wireless HC-05/HC-06 Bluetooth driving with dynamic PWM speed tiers, honk alerts, and fail-safe safety watchdogs.

Roadmap: 🚗 Day 1: Motors & Power 🛠️ Day 2: Chassis Assembly 🎮 Day 3: Serial & RC Driving 📡 Day 4: Autonomous Radar

1. 🎯 Session Overview & Learning Objectives

Building upon the mechanical chassis assembled on Day 2, Day 3 transforms the robot car into an interactive teleoperated vehicle:

2. 🔌 Complete Hardware Architecture & Bluetooth Wiring

+-------------------------------------------------------------------------------+ | CONNECT ROBO DAY 3: PC SERIAL & BLUETOOTH RC CAR ARCHITECTURE | +-------------------------------------------------------------------------------+ +-------------------+ +-------------------+ | LEFT TT MOTOR | | RIGHT TT MOTOR | +--------+----------+ +---------+---------+ | | +------------+ +------------+ | | v v +-----------------------------------------------------+ | L298N DUAL H-BRIDGE | | | | [OUT1 OUT2] [OUT3 OUT4] | | | | ENA IN1 IN2 IN3 IN4 ENB +12V GND +5V | +---+-----+-----+-----+-----+-----+-----+---+----+----+ | | | | | | | | | | | | | | | | | +---> 5V Logic | | | | | | | | | | | | | | | +----------+ | | | | | | | | (Common GND) | | | | | | +-------+ | | | | | | | | | | | | | | | +----+---+ | | | | | | | | SWITCH | | | | | | | | +----+---+ | | | | | | | | | | | | | | | | (+) | (-) | | | | | | +----+-------+-----+ | | | | | | | 2x 18650 LI-ION | | | | | | | | PACK (7.4V) | | | | | | | +------------------+ | | | | | | v v v v v v +-----------------------------------+ | Pin5 Pin6 Pin7 Pin8 Pin9 Pin10| | | | ARDUINO UNO R3 | | | | Pin2 (SoftRX) Pin3 (SoftTX) | | ^ | | | | v | | | [ 1k Resistor]| | | +-------+---> HC-05 RXD (3.3V Safe) | | | | | [ 2k Resistor] | | | | | GND | | | | | HC-05 MODULE | | | +---------------+ | | +----+ TXD | | | | VCC (+5V) | | | | GND ----------+-+ | +---------------+ | | | Pin4 -> Active Buzzer (+) | | GND -----------------------------+ +-----------------------------------+
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!

3. 🌟 The 5 Golden Rules of Wireless Bluetooth Robotics

⚡ Golden Rule 1: Use SoftwareSerial on Pins 2 & 3 (Avoid Pins 0 & 1)

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.

🛡️ Golden Rule 2: 3.3V Logic Protection for HC-05 RXD

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.

⏱️ Golden Rule 3: Fail-Safe Safety Watchdog Timer

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.

📻 Golden Rule 4: Distinct Baud Rates (115200 for PC vs. 9600 for BT)

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!

📲 Golden Rule 5: Bluetooth Pairing Code (1234 or 0000)

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.

4. 📋 10-Point Student Wireless Inspection Checklist

Checklist Completion: 0 / 10 (0%)
1. SoftwareSerial Check: HC-05 TXD connects to Pin 2; HC-05 RXD connects to Pin 3 via resistor divider.
2. Hardware Serial Clear: Arduino Pins 0 (RX) and 1 (TX) remain completely empty.
3. Common Ground Link: Battery (−), L298N GND, and Arduino GND are all tied together.
4. Jumper Caps Removed: ENA and ENB black jumper caps are off, connected to Pins 5 & 10.
5. Buzzer Polarity: Active Buzzer positive lead connected to Pin 4; negative lead to GND.
6. Serial Monitor Baud: PC Serial Monitor set to 115200 Baud for Sketch 1.
7. Elevated Bench Test: Robot car supported on a stand so wheels spin freely during keyboard tests.
8. Bluetooth LED Status: HC-05 power LED is blinking, ready for phone pairing.
9. App Command Mapping: Smartphone RC app set to send single characters ('F', 'B', 'L', 'R', 'S').
10. Safety Watchdog Verification: Press 'F' once — verify car stops automatically after 3 seconds without input.
🚀 100% PRE-FLIGHT CLEARANCE VERIFIED! All hardware connections confirmed. Flip Battery Switch ON!

5. 💻 Verified Firmware Sketches

Sketch 1: PC_SERIAL_ROBOT_CAR_V2.ino (Keyboard Serial Control & Speed Tiers)
/*
 * 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)"));
}
Sketch 2: BLUETOOTH_HC05_ROBOT_CAR.ino (Wireless Smartphone RC Driving)
/*
 * 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);
}

6. 🩺 Classroom Troubleshooting Matrix

Quick Filters:
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).