Arduino sketch for parsing serial commands to control Chainable RGB LED via Serial3.
bluetooth_serial_controller/
├── bluetooth_serial_controller.ino # Main sketch
├── LEDController.h # LED controller class header
├── LEDController.cpp # LED controller implementation
├── CommandParser.h # Command parser class header
└── CommandParser.cpp # Command parser implementation
- Open Arduino IDE
- Go to File → Open
- Navigate to
bluetooth_serial_controller/bluetooth_serial_controller.ino - The IDE will load all source files in the sketch folder
This sketch receives text commands over Serial3 and controls a Chainable RGB LED (Grove LED). It is designed to work with Bluetooth serial modules (e.g., HC-05, HC-06) connected to Serial3.
- Arduino MEGA 2560
- Grove Chainable RGB LED (1 LED)
- Bluetooth module (HC-05/HC-06) - optional
| MEGA 2560 Pin | Component |
|---|---|
| Pin 13 | CLK (Clock) |
| Pin 12 | DI (Data In) |
| 5V | VCC |
| GND | GND |
| MEGA 2560 Pin | Bluetooth Pin |
|---|---|
| Pin 15 (TX3) | RX |
| Pin 14 (RX3) | TX |
| 5V | VCC |
| GND | GND |
| Port | Baud Rate | Purpose |
|---|---|---|
| Serial | 9600 | Debug output / status messages |
| Serial3 | 38400 | Command input (from Bluetooth) |
| Command | Description | Example |
|---|---|---|
rXXX gYYY bZZZ |
Set all three RGB values (0-255) | r100 g200 b50 |
rXXX |
Set red value only (0-255) | r100 |
gXXX |
Set green value only (0-255) | g200 |
bXXX |
Set blue value only (0-255) | b50 |
rnd |
Set random color (each R, G, B randomly 0-255) | rnd |
| Command | Description | Example |
|---|---|---|
on |
Turn LED on | on |
off |
Turn LED off | off |
flash |
Enable flashing mode | flash |
steady |
Disable flashing mode (steady) | steady |
hue |
Enable hue cycle mode | hue |
hue_off |
Disable hue cycle mode | hue_off |
speed XXX |
Set animation speed (0-10000 ms) | speed 500 |
| Command | Description | Default | Example |
|---|---|---|---|
sat X.X |
Set saturation (0.0-1.0) | 1.0 | sat 0.5 |
bright X.X |
Set brightness (0.0-1.0) | 0.5 | bright 0.8 |
After each command, the system prints current values:
rXXX gYYY bZZZ on=true/false flash=true/false hue=true/false speed=XXX sat=X.X bright=X.X
- Wire the Chainable RGB LED to MEGA 2560 (CLK→13, DI→12, VCC→5V, GND→GND)
- Upload the sketch to Arduino
- Connect Bluetooth module to Serial3 (optional)
- Send commands via Serial3 at 38400 baud
r255 g0 b0 → Sets red to max
r100 → Sets red to 100
g200 → Sets green to 200
b50 → Sets blue to 50
rnd → Random colors
on → LED turns on
flash → LED starts flashing
steady → LED stops flashing
hue → Hue cycle starts
hue_off → Hue cycle stops
speed 500 → Animation speed = 500ms
sat 0.5 → Saturation = 0.5
bright 0.8 → Brightness = 0.8
The hue mode cycles through colors automatically. Use sat to control color intensity and bright to control brightness:
on
hue
speed 100
sat 1.0
bright 0.7
The flash mode toggles between your selected color and off:
on
r255 g255 b0
flash
speed 200
This sketch requires the ChainableLED library by Seeed Studio.
- Open Arduino IDE
- Go to Sketch → Include Library → Manage Libraries
- Search for "ChainableLED"
- Install "Grove Chainable LED" by Seeed Studio
- Invalid color values are automatically constrained to 0-255
- Invalid saturation/brightness are constrained to 0.0-1.0
- Unknown commands are silently ignored
- Commands are case-sensitive