English | 繁體中文
A prototype smart car controlled via Bluetooth from a smartphone, built with ESP32 + MicroPython. Implements Nordic UART Service (NUS) for BLE communication, I2C PWM motor control, and connection status indication.
🎥 Demo Video: Watch on GitHub
An entry-level embedded project focused on Bluetooth communication and hardware integration. Goals:
- Learn BLE (Bluetooth Low Energy) and the Nordic UART Service (NUS) standard
- Learn I2C bus and integrate the PCA9685 PWM expander
- Practice MicroPython firmware development on ESP32
- Build a full Mobile App → Firmware → Hardware control chain
Scope clarification: This project focuses on the application layer (communication and control logic). Low-level PWM/I2C drivers are referenced from open-source MicroPython community libraries (see Credits).
| Feature | Description |
|---|---|
| BLE Connection Management | ESP32 advertises as ESP32_F; smartphone can connect and send commands |
| Connection Status LED | Onboard LED blinks at 1Hz when disconnected, stays on when connected |
| Command Parsing | Receives UTF-8 text commands and triggers corresponding actions (e.g. blue_led toggles LED) |
| Motor Control | 4-channel DC motor forward / reverse / brake with adjustable speed |
| Servo Control | Supports degree / radian / microsecond / duty cycle input modes |
┌──────────────────┐ ┌──────────────────┐ ┌────────────────────┐
│ Smartphone │◀──BLE──│ ESP32 │──I2C──▶│ PCA9685 │
│ (BT Terminal) │ (NUS) │ MicroPython │ │ 16-ch PWM Driver │
└──────────────────┘ └──────────────────┘ └────────────────────┘
│ │
│ ├──▶ 🔧 DC Motor × 4
│ │ (forward/back/steer)
│ │
│ └──▶ 🎯 Servo × N
│ (angle control)
▼
┌──────────────────┐
│ Status LED │
│ (GPIO 2) │
│ · Slow blink │
│ = waiting │
│ · Solid on │
│ = connected │
└──────────────────┘
| Component | Specification | Purpose |
|---|---|---|
| MCU | ESP32 DevKit (dual-core 240MHz, built-in Wi-Fi/BLE) | Main controller + BLE |
| PWM Driver | PCA9685 (I2C, 16 channels, 12-bit resolution) | Unified PWM signal generation |
| Motor Driver IC | H-bridge (e.g. L298N / TB6612FNG) | Provides bidirectional motor current |
| DC Motor | 6V TT Gear Motor × 4 | 4-wheel drive |
| Servo | SG90 / MG90S (optional) | Front-wheel steering |
| Power | 7.4V Li-ion battery pack + LDO regulator | Separate supply for MCU and motors |
| Status LED | Onboard blue LED (GPIO 2) | BLE connection indicator |
Remote-Controlled-RC-Smart-Car/
├── bluetooth.py ⭐ Self-implemented — BLE communication + command parsing + status LED
├── motor.py Referenced · Adafruit MicroPython DC Motor wrapper
├── servo.py Referenced · Adafruit MicroPython Servo wrapper
└── pca9685.py Referenced · MicroPython community PCA9685 I2C driver
class BLE(): def __init__(self, name): self.ble = ubluetooth.BLE() self.ble.active(True) self.led = Pin(2, Pin.OUT) self.timer1 = Timer(0) self.timer2 = Timer(1) self.disconnected() # start in disconnected state self.ble.irq(self.ble_irq) # register event callback self.register() # register Nordic UART Service self.advertiser() # start advertising
What this code does:
- Uses ESP32 hardware Timers and BLE IRQ callbacks to handle connect/disconnect events and incoming messages, avoiding a while-loop polling pattern
- Two Timers alternately toggle the LED to produce a blinking "on / off" pattern as a not-connected indicator
- Reuses the Nordic UART Service (NUS) UUIDs so that generic mobile apps like nRF Connect or Serial Bluetooth Terminal can connect directly
This project uses the Nordic UART Service (NUS) standard, widely supported by apps such as nRF Connect and Serial Bluetooth Terminal:
| UUID | Name | Direction | Property |
|---|---|---|---|
6E400001-B5A3-F393-E0A9-E50E24DCCA9E |
Service UUID | - | - |
6E400002-B5A3-F393-E0A9-E50E24DCCA9E |
RX Characteristic | Phone → ESP32 | WRITE |
6E400003-B5A3-F393-E0A9-E50E24DCCA9E |
TX Characteristic | ESP32 → Phone | NOTIFY |
| Command | Action |
|---|---|
blue_led |
Toggle GPIO 2 blue LED state |
| (extensible) | forward, backward, left, right, stop, etc. |
Signal flow:
Phone App ─write→ RX Char ─IRQ→ ble_irq() ─decode→ command dispatch → hardware action
# Install esptool pip install esptool # Erase flash esptool.py --port /dev/tty.SLAB_USBtoUART erase_flash # Flash MicroPython firmware (download from micropython.org/download/esp32/) esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART \ write_flash -z 0x1000 esp32-20240602-v1.23.0.bin
Using Thonny IDE:
- Open Thonny →
Tools→Options→Interpreter→ selectMicroPython (ESP32) - Choose the correct serial port
- Open all 4
.pyfiles in this project; for each:File → Save as → MicroPython device
- Android: Serial Bluetooth Terminal
- iOS: nRF Connect
- Power on ESP32 → advertising begins (LED slow blink)
- Open mobile app, scan for
ESP32_F, connect - Once connected, LED stays solid on
- Send commands (e.g.
blue_led) to control the car
# main.py (running on ESP32) from machine import Pin, I2C from bluetooth import BLE import motor # Initialize BLE ble = BLE("ESP32_F") # Initialize I2C + motors i2c = I2C(0, scl=Pin(22), sda=Pin(21)) motors = motor.DCMotors(i2c, address=0x60) # Move forward: motor 0 clockwise, speed 3000 (range 0-4095) motors.speed(0, 3000)
- Basics of BLE communication — how advertising works, how a client connects, and how to receive commands
- Basic I2C usage — got hands-on exposure via the PCA9685 driver
- How PWM controls motor speed — grasped the role of duty cycle
- MicroPython firmware workflow — uploading via Thonny IDE, testing in REPL, debugging with
print() - Reading and using open-source drivers — learned to leverage existing libraries instead of writing everything from scratch
- Phase 1: BLE communication (NUS standard compliant)
- Phase 2: LED status indication (Timer + IRQ event-driven)
- Phase 3: Integrate PCA9685 + DC motor + Servo control
- Phase 4: Extend command protocol — support parameterized commands (e.g.
forward:200,turn:left:30) - Phase 5: Failsafe — auto-stop within 3 seconds of BLE disconnect
- Phase 6: Add HC-SR04 ultrasonic sensor → autonomous obstacle avoidance
- Phase 7: Custom mobile app (React Native / Flutter) replacing generic BLE Terminal
- Phase 8: Add IMU (MPU6050) → self-balancing car or attitude awareness
This project focuses on upper-layer BLE communication and application logic. Hardware drivers are referenced from the following open-source libraries:
| File | Source | License |
|---|---|---|
pca9685.py |
MicroPython PCA9685 driver | MIT |
motor.py |
Adafruit MicroPython Motor library | MIT |
servo.py |
Adafruit MicroPython Servo library | MIT |
Standard protocols referenced:
If this project is developed further, the most valuable directions:
- From "remote-controlled" to "self-driving": Add ultrasonic / optical flow / SLAM → let the car make autonomous decisions
- From "single unit" to "multi-robot cooperation": ESP-NOW protocol for inter-car communication → convoy formation
- From "BLE" to "Wi-Fi + MQTT": Integrate with IoT platforms (AWS IoT / Home Assistant)
- Add ML inference: TensorFlow Lite Micro on ESP32-S3 → vision-based obstacle avoidance
- Power management optimization: Deep sleep + wake-on-BLE for extended battery life
- Author: CHIU TZU HUA (邱子驊)
- Email: [email protected]
- GitHub: github.com/tzuhua0308
This project is part of my portfolio demonstrating end-to-end embedded system integration — from firmware to hardware to mobile control.