I wanted to add some cool lighting effects to some of my projects and thought I would start playing around with some RGB LED’s. I want to be able to use my Android device to control the color of the RGB LEDs. I will use an Arduino to control the RGB LED. I will also need a Bluetooth Module to have communications between the Arduino and my Android phone.
Here is the video demo of the completed project….
The RGB LED Research
From my quick research around the web, it turns out that a RGB LED is a pretty simple device. It essentially is just 3 small LEDs all bunched into one dome. Here is a crude diagram to illustrate…
My diagram is for a common cathode RGB LED. There is one ground pin and whichever color LED has a high enough voltage on its leg, it will turn on and glow. The brightness of the color will depend on the voltage level. Note:There are also common anode RGB LED’s where there are 3 grounds and 1 positive pin but I find that would be less intuitive to use.
- A HC-06 Bluetooth module (bought for $5.01 USD)… to use my phone’s Bluetooth to send commands to the Arduino which will control the LED color. See my post Simple Android to Arduino Bluetooth Communication for more details on how to get communications between the Arduino and HC-06 and where I purchased my module.
- Arduino Pro Mini (bought for $3.08 USD)… to control the RGB LED colors and take commands from my Andriod phone through the HC-06 Bluetooth module. See my post Ardiuno Pro-Mini Bring Up for more details and where I purchased my module.
- 4 way level shifter ($1.82 USD at http://www.banggood.com/Logic-Level-Converter-Bi-Directional-IIC-4-Way-Level-Conversion-Module-p-938774.html)… between my 5V Arduino and 3V HC-06 BT module.
- Mini DC-DC Converter module ($1.55 USD at http://www.banggood.com/Mini-DC-DC-Converter-Step-Down-Module-Adjustable-Power-Supply-p-920327.html)
- RGB LED ($5.99 at http://www.amazon.com/gp/product/B006S21SAK/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1)
The Hardware Diagram
The Arduino Sketch
The Arduino sketch consist of a loop that reads all the characters coming in on a SW UART looking for key words. The SW UART is connected to the Bluetooth module which is paired to an Android phone running a custom app sending requests to control the colors of the RGB LED. Once a key word is found, the line is parsed to determine the color and value to set. The Android app sends a command with the letter for the color and value between 0 to 255. The value is the analogWrite value for the PWM pin connected to the corresponding LED color. You can download the full Arduino sketch here: https://drive.google.com/file/d/0B1a0nPfCQQvKS3lCVkJ3czlpbEk/view?usp=sharing. You will need to have the companion Android app below to make it work.
The Android App
I used MIT’s AppInventor platform to make the companion Android app to send color request through a Bluetooth interface to my Arduino via a HC-06 Bluetooth module. I based it off of the AppInventor project described in my previous post “Simple Android to Arduino Bluetooth Communication”. I added 3 slide bars, 1 for each color LED. There are also 3 text boxes that get updated with the slide bar position whenever the slide bar position changes. In addition to updating the text box, the value is also concatenated into a “[color letter]:[value]|” command to be sent through the BT interface which is picked up by the Arduino sketch as described above. Here is a snapshot of the screen setup… Here are the relevant AppInventor blocks… If you would like to install the app on your device, you can get the .apk file here…. https://drive.google.com/file/d/0B1a0nPfCQQvKOHdwdFdhX2pnajQ/view?usp=sharing If you are familiar with the AppInventor environment and would like the .aia file to look at all the blocks an play around with it yourself, you can get it here… https://drive.google.com/file/d/0B1a0nPfCQQvKeGtXV21nQm5jMXM/view?usp=sharing
You can see a quick demo video of the setup working at the top of this post. After playing around with it some more, I do find there are sometimes glitches in the setup. The color jumps and then self corrects if I slide one of the colors too fast. Most likely loss of characters during Bluetooth transfer or the 9600 serial port baud rate SW UART is too slow to keep up. I could probably put in some error checking in the string received, but this is just for simple demos for now. If I really want this to be in some more elaborate project, I will add the error handling.