Bluetooth controlled RGB light strip

In December last year we developed a small Bluetooth controlled RGB light strip for the christmas tree, to be controlled with your Android smartphone

The demonstration of the project and the smartphone control can be seen in the video below.

The main aspect of the project is to use an Arduino to parse incoming Serial commands to enable and set different effects for the attached RGB strip.
The code for the project, including the Arduino code and the Android application project, can be found on GitHub: AndroidControllableLights

Another interesting aspect of the project was to enable wireless update of the Arduino sketch, using the Bluetooth serial connection. Scroll down in this post if you are only interested in figuring out how this can be done.

RGB Strip
The RGB strip contains 50 pixels, each with an individual WS2801 chip. These chips makes it possible to control the colors of each pixel on the strip using serially clocked and latched data with only 2 pins. The data pin of the strip is connected to Arduino pin 8, while the clock pin is connected to pin 9.
By using the WS2801 library by Adafruit the control of the colors on the strip is fairly easy task.

setStripColor(R, G, B);
strip.show();

Animations and effects
The next step is the control of the lights and some different effects and animations.
In this project I have decided to make the following effects:

Set color directly

Fading between set colors

Snap between set colors

Scroll of set color pattern

Running fade og set colors

Parsing of Serial commands
We are now ready to parse incoming Serial data and interpret it as commands to enable, set or disable the effects.
I decided to make the following commands which is then parsed when received Serially, either from the Bluetooth module or from a PC connected using USB.
The first byte of a command package is the command byte, descriping the command of the package. The next bytes are all parameters as described below. Each parameter is terminated with a ‘;’ character, also when only one parameter is needed.

The project contains the following commands:

0x0F – Set color [Parameters: 3 bytes of 3 char each]

0×01 – Add fade color [Parameters: 3 bytes of 3 char each]

0×02 – Reset fade colors [Parameters: None]

0×03 – Set Speed/Delay [Parameters: 1 integer of 5 chars]

0×04 – Enable fade effect [Parameters: None]

0×05 – Add snap color [Parameters: 3 bytes of 3 char each]

0×06 – Reset snap colors [Parameters: None]

0×07 – Enable snap effect [Parameters: None]

0×08 – Add scrolling color [Parameters: 3 bytes of 3 char each]

0×09 – Reset scrolling colors [Parameters: None]

0x0A – Enable scrolling effect [Parameters: None]

0x0B – Add running fade color [Parameters: 3 bytes of 3 char each]

0x0C – Reset running fade colors [Parameters: None]

0x0C – Enable running fade effect [Parameters: None]

0x0E – Disable any effect [Parameters: None]

Android Application
The most difficult part for me was the Android application.
I managed to put down a relatively simple but powerfull application to control send the specific Serial commands over Bluetooth to the Arduino.
The Android project can also be found on GitHub: ColorLightsController

So you will have to change this accordingly before starting the application on your own phone.

Wirelles (Bluetooth) update of the Arduino
One final aspect of the project, was the ability to update the Arduino sketch wirelessly, so I didn’t always have to connect a USB cable.
As the Bluetooth module I am using doesn’t have any DTR pin for resetting the board, starting the Arduino bootloader, I had to improvise and implement this “reset into bootloader” myself.

I started trying the most known reset solution, the Watchdog. But the problem with our goal in resetting into the bootloader is, that when you do a Watchdog reset an internal flag is set which then skips the bootloader.
So a real “hardware” reset is necessary.

A solution for this was to connect an analog output pin (PWM pin) to the Reset pin of the Arduino. I decided to use pin 7.
By using an Analog output pin the state of it is left unchanged while the Arduino is booting, making sure that it doesn’t go into a “restart-loop”.

We are now able to hardware-reset the board by writing 0 to that pin (GND), which sets it up and drives the reset pin low!

void resetIntoBootloader(void){
analogWrite(7, 0);}

While we have now overcome the issue of the DTR connection we still need to know when to execute the resetIntoBootloader function.
This is where the specific Arduino bootloader character sequence comes in handy.

When you press the upload button of your Arduino IDE your board is reset due to the DTR pin and the IDE then starts spitting out “0 0 0 0 0 “.
We can use this sequence to check for a zero and then a space, and if that is recognized then execute the resetIntoBootloader function.

Everytime we receive a character we need to check it with this ‘checkBootloader’ function first, to see if it is some bootloader characters.

I have implemented this in the top of the main loop, before doing any of the command parsing.
So for everytime we receive a character we check it to see if it is a bootloader character, and if not, we are going to parse it as a command byte.

Finally you will have to remember to set your Bluetooth module to a Baud-rate of 57600 – as this is the rate the Arduino bootloader is using.
That is also why the sketch is set to use 57600 as the buad-rate.

I guess this is it for now.
I hope you enjoyed this small but handsome Christmas lighting project.

Well, since you have share all this information know-how about this project, then I got an Arduino UNO, an HTC Sensation Android phone, 100 led pixels with the WS2801 driver and I’m waiting for the bluetooth adapter HC-06, however, when I tried to mount your Android project on Eclipse, it shows 59 errors (only 4 different errors), but in the Arduino it’s all fine with the code!

The errors are:

- AmbilWarnaDialog cannot be resolved to a type
- OnAmbilWarnaListener cannot be resolved to a type
- R cannot be resolved to a variable
- The import yuku cannot be resolved

I suppose that if we resolve each one of these, all the rest is gonna be solved too. Can you help me on this, please? Could be the way that I mounted the project in Eclipse? I would love if I could run this on my phone, it would be very very handy and helpful.

@James
The reason for the errors you are getting is due to the missing AmbilWarna library.
I have now updated the Git repository to include this library the right place.

So what you should do now is to pull the latest files from the repository and import both projects by using “File->Import->Existing Projects into Workspace” and then select the main cloned Git repository folder.
You should then see two projects being imported -- this is OK and you press Finish.

Sorry, but we haven’t been working on this project for a while, so support for >=4.1 has not been added yet.
Feel free to fork the code from Github and make the necessary changes to add this support, and then send us a pull request.
Regards Thomas