How to Make android app for controlling RGB LED

Here's a step by step tutorial for controlling an RGB LED from android mobile using android app created with the help of MIT app inventor.

This example is simple easy to do android app with the help of MIT app inventor to use with arduino. this will serve the newbie and novice who wants to play with android and arduino. without going much deeper in the programming side.

We all start with microcontroller by lighting some LED's. Here we going to light up an RGB LED through arduino. 

what are the components we need to achieve this? 
arduino uno or any other microcontroller
Bluetooth Module (HC-05)
RGB LED.
Anroid Phone.





check this post here to know How to transfer MIT app to your mobile phone.


Arduino Program
_____________________________________________________________________________________

#include <SoftwareSerial.h>

SoftwareSerial BT(10, 11); //TX, RX respetively
String color;

void setup() {
 BT.begin(9600);
 Serial.begin(9600);
  pinMode(2, OUTPUT); // blue
  pinMode(3, OUTPUT); // green
  pinMode(4, OUTPUT); // red

}
//-----------------------------------------------------------------------//  
void loop() {
  while (BT.available()){  //Check if there is an available byte to read
  delay(10); //Delay added to make thing stable 
  char c = BT.read(); //Conduct a serial read
  color += c; //build the string- "blue, red and green"
  }  
  if (color.length() > 0) {
    Serial.println(color); 

  if(color == "blue") 
  {
    digitalWrite(2, HIGH);
    digitalWrite (3, LOW);
    digitalWrite(4,LOW);
    delay(20);
  } 
  
  else if(color == "green") 
  {
    digitalWrite(2, LOW);
    digitalWrite (3, HIGH);
    digitalWrite(4,LOW);
    delay(20);
  }
  
  else if (color == "red")
  {
    digitalWrite(2, LOW);
    digitalWrite (3, LOW);
    digitalWrite(4,HIGH);
    delay(20);
    
  }
  
    else if (color == "stop")
  {
    digitalWrite(2, LOW);
    digitalWrite (3, LOW);
    digitalWrite(4,LOW);
    delay(20);
    
  }
  
  
color ="";}} //Reset the variable

_____________________________________________________________________________________


2 comments: