Introduction: Bluetooth Controlled Led Lights
This instructable is about how to control a RGB led light from bluetooth. A RGB led is the one which has a all the three basic led color i.e red,blue and green in a single led. I would be telling you how can you control it from your smartphone. I am not going to use inbuilt bluetooth of the linkit one because it i can not be use with any smartphone app. We would be using a external Bluetooth module.
Step 1: Gather Parts
Here are the required by you:
- linkit one
- Arduino bluetooth module
- RGB led
- breadboard
- jump wires
- A smartphone
Step 2: Connecting Bluetooth Module
We are not using the inbuilt bluetooth module of linkit one as it takes a lot of time to connect with a device and it bluetooth module also don't work with all apps. Instead of that we would be using the bluetooth module that we use in arduino projects i.e HC-05 or HC-06. This module is comparatively easy to use and to program and pairing of this module is also not very though. Here are its connections:
- vcc of module-----vcc of the board
- gnd of module-----gnd of the board
- rx of the module-----tx of the board
- tx of the module-----rx of the board
Step 3: Connect the RGB Led
I gave you a little description about RGB in the introductions. It is the led with red,blue and green color combined together in a single package. There are two types of RGB led depending upon the lead. They are common cathode or common anode. Here, only common cathode led can be used. Connect the led as follow:
- gnd of led-----gnd of board
- red pin of led-----digital pin 3
- green pin of led-----digital pin 5
- blue pin of led-----digital pin 6
Step 4: Upload the Code
Here is the code you need to upload to your linkit one board:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
const int redPin2 = 9;
const int greenPin2 = 10;
const int bluePin2 = 11;
#define REDPIN 3
#define GREENPIN 5
#define BLUEPIN 6
#define FADESPEED 5
void setup() {
// initialize serial:
Serial.begin(9600);
// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(redPin2, OUTPUT);
pinMode(greenPin2, OUTPUT);
pinMode(bluePin2, OUTPUT);
Serial.print("Arduino control RGB LEDs Connected OK ( Sent From Arduinno Board )");
Serial.print('\n');
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();
int red2 = Serial.parseInt();
// do it again:
int green2 = Serial.parseInt();
// do it again:
int blue2 = Serial.parseInt();
// look for the newline. That's the end of your
// sentence:
if (Serial.read() == '\n') {
// constrain the values to 0 - 255 and invert
// if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
// This is for COMMON ANODE
//red = 255 - constrain(red, 0, 255);
//green = 255 - constrain(green, 0, 255);
//blue = 255 - constrain(blue, 0, 255);
red = constrain(red, 0, 255);
green = constrain(green, 0, 255);
blue = constrain(blue, 0, 255);
red2 = constrain(red2, 0, 255);
green2 = constrain(green2, 0, 255);
blue2 = constrain(blue2, 0, 255);
// fade the red, green, and blue legs of the LED:
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
analogWrite(redPin2, red2);
analogWrite(greenPin2, green2);
analogWrite(bluePin2, blue2);
// print the three numbers in one string as hexadecimal:
Serial.print("Data Response : ");
Serial.print(red, HEX);
Serial.print(green, HEX);
Serial.println(blue, HEX);
}
}
}
Step 5: Download the App
you would be needing a app to control your led from your phone. Go on play store and search for "Arduino bluetooth RGB LEDs". click on the app and install it. After installing, open the app and pair your bluetoth device to your smartphone and connect to it. Then start using your app and you will be able to control the leds from your phone
Step 6: END
this is the end of the instructable. hope you like it. For any query comment below. Now go and play with your leds.