This post is about choosing color for the RGB LED light from the android app, I used slider to control the LED colors.
Circuit Diagram for common anode RGB LED:
#include <SoftwareSerial.h>
int bluetoothTx = 7;
int bluetoothRx = 8;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
pinMode(3,OUTPUT); // blue pin of RGB LED
pinMode(5,OUTPUT); // Green pin of RGB LED
pinMode(6,OUTPUT); // Red pin of RGB LED
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}
void loop()
{
//Read from bluetooth and write to usb serial
if(bluetooth.available()>= 2 )
{
unsigned int color1 = bluetooth.read();
unsigned int color2 = bluetooth.read();
unsigned int color = (color2 *256) + color1;
Serial.println(color);
if (color >= 1000 && color <1255){
int blue = color;
blue = map(blue, 1000,1255,0,255);
int blue1 = 255-blue;
analogWrite(6,blue1);
Serial.println(blue1);
delay(10);
}
if (color >=2000 && color <2255){
int green = color;
green = map(green,2000,2255,0,255);
int green1 = 255 - green;
analogWrite(5,green1);
Serial.println(green1);
delay(10);
}
if (color >=3000 && color < 3255){
int red = color;
red = map(red, 3000, 3255,0,255);
int red1 = 255 - red;
analogWrite(3,red1);
Serial.println(red1);
delay(10);
}
}
}
Arduino program for common cathode RGB LED:
#include <SoftwareSerial.h>
int bluetoothTx = 7;
int bluetoothRx = 8;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
pinMode(3,OUTPUT); // blue pin of RGB LED
pinMode(5,OUTPUT); // Green pin of RGB LED
pinMode(6,OUTPUT); // Red pin of RGB LED
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}
void loop()
{
//Read from bluetooth and write to usb serial
if(bluetooth.available()>= 2 )
{
unsigned int color1 = bluetooth.read();
unsigned int color2 = bluetooth.read();
unsigned int color = (color2 *256) + color1;
Serial.println(color);
if (color >= 1000 && color <1255){
int blue = color;
blue = map(blue, 1000,1255,0,255);
analogWrite(6,blue);
Serial.println(blue);
delay(10);
}
if (color >=2000 && color <2255){
int green = color;
green = map(green,2000,2255,0,255);
analogWrite(5,green);
Serial.println(green);
delay(10);
}
if (color >=3000 && color < 3255){
int red = color;
red = map(red, 3000, 3255,0,255);
analogWrite(3,red);
Serial.println(red);
delay(10);
}
}
}
Circuit Diagram for common anode RGB LED:
Circuit Diagram for common cathode RGB LED:
components needed for this project:
Arduino Uno
RGB LED
Bluetooth Module
Connecting Wires
Breadboard
Android app created using MIT app inventor, which is very simple, 3 sliders had created to assign values of primary colors RGB, when these sliders are moved these different colors are mixed and shown in the canvas, same color code will be send to the arduino.
Android app:
android app can be download from this link
Blocks to create Android app:
Arduino Program to control Common anode LED:
#include <SoftwareSerial.h>
int bluetoothTx = 7;
int bluetoothRx = 8;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
pinMode(3,OUTPUT); // blue pin of RGB LED
pinMode(5,OUTPUT); // Green pin of RGB LED
pinMode(6,OUTPUT); // Red pin of RGB LED
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}
void loop()
{
//Read from bluetooth and write to usb serial
if(bluetooth.available()>= 2 )
{
unsigned int color1 = bluetooth.read();
unsigned int color2 = bluetooth.read();
unsigned int color = (color2 *256) + color1;
Serial.println(color);
if (color >= 1000 && color <1255){
int blue = color;
blue = map(blue, 1000,1255,0,255);
int blue1 = 255-blue;
analogWrite(6,blue1);
Serial.println(blue1);
delay(10);
}
if (color >=2000 && color <2255){
int green = color;
green = map(green,2000,2255,0,255);
int green1 = 255 - green;
analogWrite(5,green1);
Serial.println(green1);
delay(10);
}
if (color >=3000 && color < 3255){
int red = color;
red = map(red, 3000, 3255,0,255);
int red1 = 255 - red;
analogWrite(3,red1);
Serial.println(red1);
delay(10);
}
}
}
Arduino program for common cathode RGB LED:
#include <SoftwareSerial.h>
int bluetoothTx = 7;
int bluetoothRx = 8;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
pinMode(3,OUTPUT); // blue pin of RGB LED
pinMode(5,OUTPUT); // Green pin of RGB LED
pinMode(6,OUTPUT); // Red pin of RGB LED
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}
void loop()
{
//Read from bluetooth and write to usb serial
if(bluetooth.available()>= 2 )
{
unsigned int color1 = bluetooth.read();
unsigned int color2 = bluetooth.read();
unsigned int color = (color2 *256) + color1;
Serial.println(color);
if (color >= 1000 && color <1255){
int blue = color;
blue = map(blue, 1000,1255,0,255);
analogWrite(6,blue);
Serial.println(blue);
delay(10);
}
if (color >=2000 && color <2255){
int green = color;
green = map(green,2000,2255,0,255);
analogWrite(5,green);
Serial.println(green);
delay(10);
}
if (color >=3000 && color < 3255){
int red = color;
red = map(red, 3000, 3255,0,255);
analogWrite(3,red);
Serial.println(red);
delay(10);
}
}
}
very nice one
ReplyDeleteHello ,
ReplyDeleteAll is OK except the leds whith the same connexions (bluetooth connexion and colrs on the screen off my smartphone is ok but the arduino do not response .
Perhaps ahd you have similar problem.
Thanks for your answer.
Not up to the mark! In the inventor in the last block you need to write slider3 instead of slider2!
ReplyDeleteHi can i get your .aia files so i can change the design of your app?
ReplyDeletePlease send it to my email:manalangjjustin@gmail.com
Why you need the aia file... it says exactly how to build the blocks above
DeleteThis comment has been removed by the author.
ReplyDeleteHey ! Can I get your Library #include ? Pleaseeee
ReplyDeleteplease send it to my email address : manalangjjustin@gmail.com
Deletehelp me please my app is getting crash and aurdino is not responding after few trials
ReplyDeleteHi I can ask you if you can send the app in .aia format so I can open it with app inventor and can i understand it better? My email is: geolmarano@yahoo.it. Thank you
ReplyDeleteHey can you explain how this
ReplyDeleteunsigned int color1 = bluetooth.read();
unsigned int color2 = bluetooth.read();
unsigned int color = (color2 *256) + color1;
Makes it work? I tried to figure it out for myself, but the bluetooth read would only ever give me values under 255. How does your math operation work out to give the desired results? I'd like to know out of curiosity, as I've been trying to get the color shift to work to no luck. Thank you for posting your code, it really helped me out.
After completing this application,I have continiously facing an "ERROR 510"
ReplyDeleteFunction Send2ByteNumber, Message could not decode"false" as an integer. If
possible can you send me your Apk file.
Most amazing MIT appinventor.Great thanks.
ReplyDeleteGreat tutorials!
ReplyDelete