# Wiring: Arduino Uno + PCA9685 + HC-05

```
ARDUINO UNO  <->  PCA9685 (16-channel servo driver)
  A4 (SDA) ----- SDA
  A5 (SCL) ----- SCL
  5V ----------- VCC        (logic only)
  GND ---------- GND
  second board (optional): same SDA/SCL/GND, bridge its A0 solder jumper -> address 0x41

SERVO POWER
  external 5-6 V (+) ---- PCA9685 V+ screw terminal
  external (-) ---------- PCA9685 GND screw terminal  AND  Uno GND   (COMMON GROUND)
  1000 uF electrolytic across V+ / GND, close to the board
  budget ~1 A per MG996R moving, 2.5 A stalled -> sixteen of them need a 10 A+ 5 V supply (UBEC)
  NEVER feed servos from the Uno's 5 V pin

HC-05  <->  UNO (SoftwareSerial, 9600 baud)
  VCC ---------- 5V
  GND ---------- GND
  TXD ---------- D10          (3.3 V logic; the Uno reads it fine)
  RXD <--------- D11 through 1 kOhm, plus 2 kOhm from RXD to GND   (5 V -> 3.3 V divider)
  EN / STATE --- unconnected
  never D0/D1 (the USB port used for flashing)

SERVOS  <->  PCA9685
  brown/black = GND, red = V+, orange/yellow = PWM, on the numbered 3-pin headers
  logical index in the app = board*16 + channel
```

## HC-05 facts

- Factory baud 9600 (38400 is only the AT-command mode). Default name `HC-05`, PIN `1234` (or `0000`).
- LED blinking fast = waiting for a connection; slow double-blink = connected.
- It needs about a second after a dropped link before it accepts a new connection.
- Keep 9600 baud with SoftwareSerial; the firmware supports other bauds (Setup → Link) but
  SoftwareSerial gets unreliable above 19200.

## Flashing

**From the phone (USB-OTG)** — Setup → *Flash over USB (OTG)*: an OTG adapter on the phone, a USB
*data* cable to the Uno. The phone powers the Uno (never the servos — keep them on their own supply).
The app flashes and verifies the built-in firmware, then stores your HC-05 baud / pins / board count
in the Uno's EEPROM. Works with genuine Unos (CDC) and CH340 / FTDI / CP210x clones; pick the 57600
bootloader option for old boards with ATmegaBOOT.

**With the Arduino IDE**

1. Library Manager → install **Adafruit PWM Servo Driver Library**.
2. Put `uno_robot_controller.ino` in a folder named `uno_robot_controller` (the app's
   Setup → Firmware → Save / Share does this for you), or flash the `.hex` with avrdude.
3. Board *Arduino Uno*, upload over USB. The HC-05 is on D10/D11, so it does not interfere.
4. Serial Monitor at 9600 baud, line ending *Newline*: `?` → `OK v1 16 1`; `M0:120` moves
   channel 0 to 120°; `H` homes; `R` relaxes; `K` shows the link settings, `K9600:10:11:1` sets them.

## First power-up

Nothing moves at boot. The first command to a channel makes that servo **jump** to the target
(its real position is unknown), so support the robot before touching the sliders the first time.
