GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tzuhua0308/Remote-Controlled-RC-Smart-Car: ESP32 + MicroPython BLE-controlled smart car with Nordic UART Service, PCA9685 PWM motor control, and status LED indicator

BranchesTags
Open more actions menu

Latest commit

 

History

9 Commits
9 Commits

Folders and files

NameName
Last commit message
Last commit date
README.md
README.md
 
 
README.zh-TW.md
README.zh-TW.md
 
 
bluetooth.py
bluetooth.py
 
 
motor.py
motor.py
 
 
pca9685.py
pca9685.py
 
 
servo.py
servo.py
 
 

Repository files navigation

English | 繁體中文


🚗 ESP32 BLE-Controlled Smart Car

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


📌 Project Positioning

An entry-level embedded project focused on Bluetooth communication and hardware integration. Goals:

  1. Learn BLE (Bluetooth Low Energy) and the Nordic UART Service (NUS) standard
  2. Learn I2C bus and integrate the PCA9685 PWM expander
  3. Practice MicroPython firmware development on ESP32
  4. 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).


🎯 Core Features

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

🧩 System Architecture

┌──────────────────┐        ┌──────────────────┐        ┌────────────────────┐
│   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  │
                            └──────────────────┘

🔩 Bill of Materials (BOM)

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

📁 Software Architecture

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

⭐ Self-Implemented Portion (bluetooth.py)

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

📡 BLE Communication Protocol

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 Format

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

🚀 Installation & Deployment

1. Flash MicroPython onto ESP32

# 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

2. Upload code to ESP32

Using Thonny IDE:

  1. Open Thonny → Tools → Options → Interpreter → select MicroPython (ESP32)
  2. Choose the correct serial port
  3. Open all 4 .py files in this project; for each: File → Save as → MicroPython device

3. Mobile App

  • Android: Serial Bluetooth Terminal
  • iOS: nRF Connect

4. Usage steps

  1. Power on ESP32 → advertising begins (LED slow blink)
  2. Open mobile app, scan for ESP32_F, connect
  3. Once connected, LED stays solid on
  4. Send commands (e.g. blue_led) to control the car

🛠 Usage Example

# 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)

📚 What I Learned

  • 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

🗺 Roadmap

  • 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

📖 Credits & References

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:

  • Nordic UART Service (NUS) Specification

🎓 Future Extensions

If this project is developed further, the most valuable directions:

  1. From "remote-controlled" to "self-driving": Add ultrasonic / optical flow / SLAM → let the car make autonomous decisions
  2. From "single unit" to "multi-robot cooperation": ESP-NOW protocol for inter-car communication → convoy formation
  3. From "BLE" to "Wi-Fi + MQTT": Integrate with IoT platforms (AWS IoT / Home Assistant)
  4. Add ML inference: TensorFlow Lite Micro on ESP32-S3 → vision-based obstacle avoidance
  5. Power management optimization: Deep sleep + wake-on-BLE for extended battery life

📬 Contact

  • 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.

About

ESP32 + MicroPython BLE-controlled smart car with Nordic UART Service, PCA9685 PWM motor control, and status LED indicator

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.