Arduino Bluetooth RGB LED

Control an RGB LED via Bluetooth using RoboRemo app

Arduino Bluetooth RGB LED

This page explains how to remote control an RGB LED using Arduino and Android phone with RoboRemo app.

Materials needed:
- Arduino UNO (or similar) + USB cable for it
- BlueSMiRF module or similar
- DC adapter for Arduino
- RGB led
- 3 resistors with value 100R
- wires
- Android phone with RoboRemo app installed

Introduction

The RGB LED is in fact 3 LEDs packed together. It has 4 pins. One pin is common for the 3 LEDs. It can be common anode (+) or common cathode (-). The RGB LED I use has common anode (+), so I connected it to +5V, and the 3 cathodes each in series with 100 Ohm resistor I connected to Arduino PWM pins. Now this means the LED will light-up when the pin is LOW, so I pass 255-val to analogWrite, where val is the value for brightness, received from RoboRemo slider.

Steps:

1.
Upload the code to your Arduino.

// Control an RGB led via Bluetooth
// using RoboRemo app
// www.roboremo.com

// Hardware setup:
// BT module   Arduino
// GND ------- GND
// VCC ------- 5V
// TX-O ------ pin0
// RX-I ------ pin1

// RGB led        Arduino
// VCC ---------- 5V
// red ----|__|-- pin9
// green --|__|-- pin10
// blue ---|__|-- pin11
//       3 x 100R

#define bluetooth Serial

int red = 9;       // LOW = on, HIGH = off
int green = 10;    // LOW = on, HIGH = off
int blue = 11;     // LOW = on, HIGH = off

char cmd[100];
int cmdIndex;

void exeCmd() {
  
  if( (cmd[0]=='r' || cmd[0]=='g' || cmd[0]=='b') && cmd[1]==' ' ) { 
    // "r", "g", "b" are the ids for red, green and blue    
       int val = 0;
       for(int i=2; cmd[i]!=0; i++) {
         val = val*10 + (cmd[i]-'0');
       }
       // if cmd is "r 100", val will be 100        
       if(cmd[0]=='r') analogWrite(red, 255-val);
       if(cmd[0]=='g') analogWrite(green, 255-val);
       if(cmd[0]=='b') analogWrite(blue, 255-val);
  } 
}

void setup() {
  
  delay(500); // wait for bluetooth module to start

  bluetooth.begin(115200); // Bluetooth default baud is 115200
  
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  
  digitalWrite(red, HIGH);  // off
  digitalWrite(green, HIGH);  // off
  digitalWrite(blue, HIGH);  // off
  
  cmdIndex = 0;
}

void loop() {
  
  if(bluetooth.available()) {
    
    char c = (char)bluetooth.read();
    
    if(c=='\n') {
      cmd[cmdIndex] = 0;
      exeCmd();  // execute the command
      cmdIndex = 0; // reset the cmdIndex
    } else {      
      cmd[cmdIndex] = c;
      if(cmdIndex<99) cmdIndex++;
    }
  }
}

2.
Connect the Bluetooth module and the RGB led:

arduino-bluetooth-rgb-led-schematic.jpg


In this example we use Hardware Serial.
But Arduino UNO also uses Hardware Serial for programming, so when you program the Arduino, you need to disconnect the Bluetooth module, and to run the circuit, you need to disconnect the USB cable and connect the Arduino DC power supply.

3.
Connect your Arduino to the DC power supply.

4.
Configure the RoboRemo interface and enjoy :)