Introduction
This project shows how to control an RGB SMD LED with HC-05 Bluetooth Module and Arduino.
The Android App contains two options to change the color of the LED, viz. Palette and Slider.
With the Palette option, you can choose the color from a color palette.
With the Slider option, you can control the intensity of each primary color (RGB).
After selecting the color, the app sends the data to the HC-05 Module. Then, Arduino reads this data and controls the LED accordingly.
For the app code, visit the video description.
Video
Wireless Photonics: Bluetooth RGB Controller
A standard RGB remote relies on terrible Infrared (IR) technology that requires exact line-of-sight to the TV. The Bluetooth HC-05 RGB LED Light project rips out the IR sensor and installs a massive 2.4GHz Serial link. By parsing multi-byte data streams from an Android Color-Picker app, the Arduino uses three massive PWM pins to seamlessly mix 16 million colors without ever looking at the light!
The Bluetooth Protocol (Hex / String Parsing)
When you drag the color wheel on an Android app to "Orange," the phone cannot just say "Orange." It transmits a raw text string, usually formatted like a hex code or a comma delimiter: R255G128B0\n.
- The HC-05 RX Pin receives this massive character string.
- The Arduino must aggressively buffer the string
while(Serial.available()). - The Index Parsing Math: You must utilize
indexOf()andsubstring()to slice the payload apart!
int rIndex = incomingData.indexOf('R');
int gIndex = incomingData.indexOf('G');
int bIndex = incomingData.indexOf('B');
String redString = incomingData.substring(rIndex + 1, gIndex);
int redPWM = redString.toInt(); // Converts the string "255" to the Math integer 255!
- Once the three integers (
redPWM, greenPWM, bluePWM) are violently extracted, the Arduino throws them straight to the output hardware!
The AnalogWrite PWM Mixing Array
An RGB LED is just three tiny, individual LEDs (Red, Green, Blue) shoved inside a single plastic dome.
analogWrite(RedPin, redPWM);(Usually Pin 9)analogWrite(GreenPin, greenPWM);(Usually Pin 10)analogWrite(BluePin, bluePWM);(Usually Pin 11)- By vibrating the three pins at different speeds, the human eye merges the photons into a single magnificent color.
R:255, G:128, B:0creates a gorgeous, blazing Orange!
Bluetooth RGB Hardware Needs
- Arduino Uno/Nano.
- HC-05 Transceiver Module (Requires a 1K / 2K resistor voltage divider on the RX pin! The Uno is 5V, the HC-05 logic is 3.3V!).
- Common Cathode RGB LED (The longest leg goes to GND).
- Or, scale it up: Use 3 Massive TIP120 NPN Transistors to drive an entire 5-meter analog 12V RGB LED strip around your entire ceiling!