Skip to content

GeoCd/bluetooth-ugv-matlab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

bluetooth-ugv-matlab

Bluetooth-controlled Unmanned Ground Vehicle (UGV) operated through a MATLAB GUI, with firmware written in C for the PIC16F887 microcontroller. Built for the Microprocesadores, Microcontroladores e Interfaz course at UPIITA, IPN around April - May 2022.


What it does

The system has four operation modes selectable from the GUI:

  • Demostración: runs a fixed choreography of movements (forward, backward, left turn, right turn, reverse turns) at a preset speed
  • Medición: triggers the HC-SR04 ultrasonic sensor, reads distance in cm, and displays the result in the GUI
  • Sig. Líneas: line following using two IR sensors, with differential PWM speed to correct trajectory
  • Control: manual Bluetooth control via directional buttons (forward, backward, left, right) with three speed levels: slow, regular, fast

Speed is controlled via PWM on both motors independently. The GUI sends two characters per command, direction, speed level and the firmware parses them via USART.


System architecture

MATLAB GUI (BTCAR.fig / BTCAR.m)
        │
        ▼
Bluetooth serial (HC-05, 9600 baud)
        │  
        ▼
PIC16F887 firmware (BTCAR.c)
        │
        ├── RA0–RA3 → H-bridge motor control
        ├── RB0 ← HC-SR04 echo
        ├── RB1 → HC-SR04 trigger
        ├── RB6–RB7 ← IR line sensors
        └── RC6/RC7 → USART TX/RX

Hardware

  • PIC16F887 microcontroller
  • HC-05 Bluetooth module
  • HC-SR04 ultrasonic distance sensor
  • 2x DC motors with H-bridge driver
  • 2x IR line sensors
  • Laser-cut wooden chassis (existing design, adapted for component integration)
  • 3D printed mounts and brackets for sensor placement

Files

File Description
BTCAR\BTCAR.c PIC16F887 firmware with USART communication, motor control, PWM, ultrasonic ranging, line following
BTCAR\BTCAR.m MATLAB GUI logic with serial port management, button callbacks, mode selection, speed control
BTCAR\BTCAR.fig MATLAB GUIDE layout file which requires MATLAB to open

GUI

GUI

The interface has three panels: connection controls (connect/disconnect), mode selection (Demostración, Medición, Sig. Líneas, Control), and speed selection (Lento, Regular, Rápido). The directional buttons and distance display are active during manual control and measurement modes respectively.

The hexagonal background theme was intentional.


Physical build

UGV front UGV top

Laser-cut wooden chassis adapted to fit the motor driver, PIC board, Bluetooth module, ultrasonic sensor at the front, and IR sensors underneath. Wiring routed manually between components.


Notes on the firmware

The PWM implementation writes directly to CCPR1L and CCP1CON using bit-shifted values from ADRESH/ADRESL.

The ultrasonic ranging uses TMR1 to measure echo pulse width. If TMR1 overflows before the echo returns, the distance is reported as 0 rather than throwing an error.

The line follower uses differential speed rather than stop-and-correct: when one sensor detects the line edge, that motor's PWM drops to 100 while the other stays at 700, steering the vehicle back on track without stopping.


Honest reflections

The most interesting part of this project wasn't the Bluetooth control. It was getting four completely different operation modes to coexist cleanly in a single main loop on a microcontroller with limited resources, each mode with its own timing requirements and hardware dependencies.

The chassis adaptation was more work than expected. The original laser-cut design wasn't made with a sensor array or Bluetooth module in mind, so fitting everything required improvising mount points and managing cable routing in a very tight space.

About

Bluetooth-controlled UGV with four operation modes: demo, ultrasonic ranging, line following and manual control. Everything driven by a PIC16F887 and operated through a MATLAB GUI.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors