Skip to main content

Android Arduino app and code for controlling RGB LED

Android Arduino app and code for controlling RGB LED

Circuit Diagram :





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



Download code : https://www.dropbox.com/s/45mv2x9zc56kvms/rgb_BLUETOOTH.ino?dl=0



Android app :








Comments