In this tutorial, we will control the RGB LED by using Android with Arduino IDE, HC-05 Bluetooth module and Surilli GSM. The color of the RGB LED is controlled by using the android application which is freeware.
What Is an RGB LED?RGB LED means red, blue and green LEDs. RGB LED products combine these three colors to produce over 16 million hues of light. Note that not all colors are possible. Some colors are “outside” the triangle formed by the RGB LEDs. Also, pigment colors such as brown or pink are difficult, or impossible, to achieve.
(Reference to: http://www.lighting.philips.com/main/support/support/faqs/white-light-and-colour/what-does-rgb-led-mean)
RGB LED used here is Common Anode Type which means the R,G and B terminals is connected to PWM pins and the final terminal is connected to VCC 5V of Surilli GSM.
Hardware Required1. HC-05 Bluetooth module
2. RGB LED (common anode)
3. Android mobile device
4. Application from Google Play Store (Color LED Controller)
5. Connecting wires
6. Surilli GSM
7. Arduino IDE
Connections Between Surilli GSM, RGB LED, and HC-05 Bluetooth Module:
RED PIN (RGB LED) ---> PIN 3 (SURILLI GSM)
GREEN PIN (RGB LED) ---> PIN 5 (SURILLI GSM)
BLUE PIN (RGB LED) ---> PIN 9 (SURILLI GSM)
+5V PIN (BLUETOOTH MODULE HC-05) ---> USB PIN (SURILLI GSM)
GND PIN (BLUETOOTH MODULE HC-05) ---> GND PIN (SURILLI GSM)
TXD PIN (BLUETOOTH MODULE HC-05) ---> PIN 11 (SURILLI GSM)
RXD PIN (BLUETOOTH MODULE HC-05) ---> PIN 12 (SURILLI GSM)
Android ApplicationDownload the "Color LED Controller" application from the Google Play Store.
The application sends the information to HC-05 Bluetooth module. The module then sends the data to the Arduino, and the color is varied by PWM pins on Arduino.
Set Up Arduino IDE for SurilliMake sure you have selected the right port, board and processor for the Surilli as shown in the picture below and it is programmable (compile and upload “Blink” from File>Examples>Digital>Blink onto your Surilli to check if everything is working fine).
The CircuitryThe circuitry is very simple. It's mostly the programming. Follow the figure below to set up your hardware.
Now you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE and hit upload.
---> After it has been uploaded, open the android app, then click on "BT List". This will show all the available bluetooth devices. Select HC-05. Then it will connect to the Bluetooth Module HC-05. After that click on the "LED Turn ON" button just next to "BT List" button. By choosing RED, it will turn on the RED LED and son on.
---> If we now press the "LED Turn OFF" button, then in the middle of app, there is a circle showing different colors. Click on Red Color to see the RED LED turning ON, click on Green Color to see GREEN LED turning ON and so on.
NOTE: Don't upload the code to Surilli GSM while Bluetooth Module is still connected to arduino. Disconnect the Bluetooth Module HC-05 before uploading the code to Surilli GSM and connect it back after uploading the program.
Arduino Code:#include <SoftwareSerial.h>
#include <Wire.h>//Include libraries: SoftwareSerial & Wire
SoftwareSerial BT(12,11); //Define PIN11 & PIN12 as RX and TX pins
//RGB LED Pins
int PIN_RED = 3;
int PIN_GREEN = 5;
int PIN_BLUE = 9;
//RED LED at Pin 13
int RED_LED = 13;
String RGB = ""; //store RGB code from BT
String RGB_Previous = "255.255.255)"; //preserve previous RGB color for LED switch on/off, default White
String ON = "ON"; //Check if ON command is received
String OFF = "OFF"; //Check if OFF command is received
boolean RGB_Completed = false;
void setup() {
Serial.begin(9600); //Arduino serial port baud rate:9600
BT.begin(9600);//My HC-05 module default baud rate is 9600
RGB.reserve(30);
pinMode(RED_LED, OUTPUT);
//Set pin13 as output for LED,
// this LED is on Arduino mini pro, not the RGB LED
}
void loop() {
// put your main code here, to run repeatedly:
//Read each character from Serial Port(Bluetooth)
while(BT.available()){
char ReadChar = (char)BT.read();
// Right parentheses ) indicates complete of the string
if(ReadChar == ')'){
RGB_Completed = true;
}else{
RGB += ReadChar;
}
}
//When a command code is received completely with ')' ending character
if(RGB_Completed){
//Print out debug info at Serial output window
Serial.print("RGB:");
Serial.print(RGB);
Serial.print(" PreRGB:");
Serial.println(RGB_Previous);
if(RGB==ON){
digitalWrite(13,HIGH);
RGB = RGB_Previous; //We only receive 'ON', so get previous RGB color back to turn LED on
Light_RGB_LED();
}else if(RGB==OFF){
digitalWrite(13,LOW);
RGB = "0.0.0)"; //Send OFF string to turn light off
Light_RGB_LED();
}else{
//Turn the color according the color code from Bluetooth Serial Port
Light_RGB_LED();
RGB_Previous = RGB;
}
//Reset RGB String
RGB = "";
RGB_Completed = false;
} //end if of check if RGB completed
} // end of loop
void Light_RGB_LED(){
int SP1 = RGB.indexOf('.');
int SP2 = RGB.indexOf('.', SP1+1);
int SP3 = RGB.indexOf('.', SP2+1);
String R = RGB.substring(0, SP1);
String G = RGB.substring(SP1+1, SP2);
String B = RGB.substring(SP2+1, SP3);
//Print out debug info at Serial output window
Serial.print("R=");
Serial.println( constrain(R.toInt(),0,255));
Serial.print("G=");
Serial.println(constrain(G.toInt(),0,255));
Serial.print("B=");
Serial.println( constrain(B.toInt(),0,255));
//Light up the LED with color code
//**2014-09-21
//Because these RGB LED are common cathode (Common negative)
//So we need to take 255 to plus R,G,B value to get correct RGB color code
analogWrite(PIN_RED, (255+R.toInt()));
analogWrite(PIN_GREEN, (255+G.toInt()));
analogWrite(PIN_BLUE, (255+B.toInt()));
}
Play with the program to see how it reacts to different values and logic.
If you make something fun and interesting, do share it with our community.
That’s all for now. If you have any queries, visit surilli.io or contact our support. Stay connected with the Surilli family for more amazing stuff. :-)



_PYYnCWORsb.png?auto=compress%2Cformat&w=900&h=675&fit=min)










Comments