Skip to content

Anqv/bluetooth-serial-controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Bluetooth Serial Controller

Arduino sketch for parsing serial commands to control Chainable RGB LED via Serial3.

Project Structure

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

Opening the Project

  1. Open Arduino IDE
  2. Go to File → Open
  3. Navigate to bluetooth_serial_controller/bluetooth_serial_controller.ino
  4. The IDE will load all source files in the sketch folder

Overview

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.

Hardware Requirements

  • Arduino MEGA 2560
  • Grove Chainable RGB LED (1 LED)
  • Bluetooth module (HC-05/HC-06) - optional

Wiring (MEGA 2560)

Chainable RGB LED

MEGA 2560 Pin Component
Pin 13 CLK (Clock)
Pin 12 DI (Data In)
5V VCC
GND GND

Bluetooth Module (Optional)

MEGA 2560 Pin Bluetooth Pin
Pin 15 (TX3) RX
Pin 14 (RX3) TX
5V VCC
GND GND

Serial Settings

Port Baud Rate Purpose
Serial 9600 Debug output / status messages
Serial3 38400 Command input (from Bluetooth)

Commands

Color Commands

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

Mode Commands

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

HSB Commands

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

Response Format

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

User Guide

Quick Start

  1. Wire the Chainable RGB LED to MEGA 2560 (CLK→13, DI→12, VCC→5V, GND→GND)
  2. Upload the sketch to Arduino
  3. Connect Bluetooth module to Serial3 (optional)
  4. Send commands via Serial3 at 38400 baud

Example Session

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

Using Hue Mode

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

Using Flash Mode

The flash mode toggles between your selected color and off:

on
r255 g255 b0
flash
speed 200

Library

This sketch requires the ChainableLED library by Seeed Studio.

Install via Arduino IDE Library Manager

  1. Open Arduino IDE
  2. Go to Sketch → Include Library → Manage Libraries
  3. Search for "ChainableLED"
  4. Install "Grove Chainable LED" by Seeed Studio

Error Handling

  • 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

About

Arduino Mega 2560 sketch: parses Bluetooth serial commands (HC-05/HC-06) to control a Grove Chainable RGB LED

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages