English
Español
PCBWAY PCB service

PCBWAY PCB service

PCBONLINE PCB service






Arduino ANDROID App RGB LED strip control



The Code PNP


There will be a different code for thr NPN schematic and other for the PNP. Just download the sketch or copy it from below. There is no extra library to install so the code should work for any Arduino IDE.



/* RGB LED strip with arduino and Android App bluetooth connection
 *  http://www.electronoobs.com
 *  
ARDUINO       RGB      
  3          RED
  5          GREEN
  9          BLUE

Bluetooth HC-06 module and Arduino
ARDUINO    Bluetooth HC-06 
 0 (RX)       TX
 1 (TX)       RX
 5V           VCC
 GND          GND
 */
///////////////////////////////pre upload ERROR////////////////////////////////////
//#error delete this line after you make sure that the Tx and Rx pin are disconnected
//Tx and Rx pins of the HC06 module should not be connected while we upload the
//"Sketch" to the arduino. The code won't be upload if the pins are connected
///////////////////////////////////////////////////////////////////////////////////
int color=0;

//define the RGB pind
int red = 3;
int green = 5;
int blue = 9;

char received;

void setup()  { 
  Serial.begin(9600);     //Start the serial comunication for the bluetooth module
  pinMode(red, OUTPUT);   //Red color pwm pin defined as output
  pinMode(green, OUTPUT); //Green color pwm pin defined as output
  pinMode(blue, OUTPUT);  //Blue color pwm pin defined as output
  
  //Give first value of the PWM 0, we start with the RGB LEDs off
  analogWrite(red,255);
  analogWrite(green,255);
  analogWrite(blue,255);

 } 
 
void loop()  { 
  
  if(Serial.available()>0){
    // read the bluetoot data and store it
    color = Serial.read();
    char Rec = char(color);
    if (Rec != '0')
    {
    Serial.println(Rec); //This is to visualise the received character on the serial monitor
    }  
  }

  //LEDs off
  if (color == 'n')
  {
    analogWrite(red,255);
    analogWrite(green,255);
    analogWrite(blue,255);
  }
  //White
  if (color == 'w')
  {
    analogWrite(red,0);
    analogWrite(green,0);
    analogWrite(blue,2550);
  }
  //Red
  if (color == 'r')
  {
    analogWrite(red,0);
    analogWrite(green,255);
    analogWrite(blue,255);
  }
  //Green
  if (color == 'g')
  {
    analogWrite(red,255);
    analogWrite(green,0);
    analogWrite(blue,255);
  }
  //Blue
  if (color == 'b')
  {
    analogWrite(red,255);
    analogWrite(green,255);
    analogWrite(blue,0);
  }
  //Orange
  if (color == 'o')
  {
    analogWrite(red,0);
    analogWrite(green,98);
    analogWrite(blue,255);
  }
  //Violet
  if (color == 'v')
  {
    analogWrite(red,148);
    analogWrite(green,255);
    analogWrite(blue,107);
  }
  //Cyan
  if (color == 'c')
  {
    analogWrite(red,255);
    analogWrite(green,0);
    analogWrite(blue,0);
  }
  //Yellow 
  if (color == 'y')
  {
    analogWrite(red,0);
    analogWrite(green,51);
    analogWrite(blue,255);
  }  
}



Final results


Now upload the code to the Arduin. Make sure that the RX and TX pins of the Bluetooth module are nopt connected while uploading the code, otherwise an error will pop out. After uploading, connect the bluetooth module, start the app, connect all the components, transistors, led stip, etc and start changeing the color.

Un vídeo publicado por ELECTRONOOBS® (@electronoobs) el


Try other Apps


In order to try other PlayStore apps download the next Arduino code. Upload it to your Arduino, connect the bluetooth module like in the past schematics and open the serial monitor. Afet you download a PlayStore App, open it, connect to the HC06 bluetooth module and start pressing one button at a time. On the serial monitor you should see each received data. Note the sended data for each button and change the LED strip code to match your colors.


Not all the apps will be compatible. Some of them will send just 3 data packs with values between 0 and 255 directly for each of the 3 basic colors PWM width.