Project tutorial
SmartPhone Controlled RGB MOOD Light

SmartPhone Controlled RGB MOOD Light © CC BY-NC-SA

Can't control your mood? Well you can control the ambiance light with your smartphone.

  • 4,565 views
  • 1 comment
  • 10 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

Mood lamps are always fascinating for me and is a very good project for starters to start with Arduino.

What is a Mood Lamp ?

Mood lamps are lighting devices that are used to establish a particular feeling or mood within a room. In some cases, this type of lamp may be a small device that is plugged into an outlet and creates points of light near the floor line of the room. Other examples of a mood lamp may be used to illuminate specific points along the walls or cast a soft light over a larger piece of furniture in the room.

Mood lighting differ somewhat from other lamps in that their purpose is not so much practical as aesthetic. Reading lamps for example tend to provide bright light to a given space in order to make it possible to read a book or magazine without creating strain on the eyes. Overhead lighting is used when there is a need to illuminate the majority of the space, such as in a classroom or laboratory. By contrast, a mood lamp is used to help create a specific ambiance within the room as a means of making the space more attractive and welcoming in some manner.

NOTE: This Tutorial is accepted for rainbow contest do vote if you like it.

Do subscribe my channel for upcoming videos.

Step 1: Components

The component list way too small but there are diversity in the list . i actually reviewed three types over the this instructables anyways the list .

  • Arduino
  • RBG led
  • HC-05
  • Jumpers
  • Bread Board

Comparison of all the variants

RGB led : Easily available in ebay and all radio shack or locals store.

High Color Output. Can be easily power withi arduino .RGB SMD : This are sold as module i test a common cathode version the seem not to work great with arduinos internal power supply. RGB LED Strip : These are the Best comes with highest color range output with a correct driver you can drive them to give insane level of colors.Indians can find these at this link.

Step 2: What is RGB Led?

Normal led emits monochromatic color output which may be red ,green, or blue.To obtain other color we need to combine the color RGB . This result in 7 different color.To produce more than 7 colors, each color channel should be able to change in brightness, not just turned on or off.A popular control method is PWM, of which the cycle duty range determines the available brightness levels. The more the levels are available, the more colors can be produced. Apart from the popularity in applications like outdoor decoration lighting in cities, stage lighting designs, home decoration lighting and LED display matrix, RGB color mixing technology can also be found recently in LCD backlighting and projectors.We learn about PWM later in this Instructables.

RGB can be be of two type

Common Cathode or Common Anode Common Cathode Three led channel has a single Cathode

Common Anode Three led channel has a single Anode

Step 3: Interfacing RGB Led & RGB Led Strips

RGB LED: In case for RGB led the interfacing is very easy we talk about both Common Cathode And Common Anode.

Common Cathode

R to any PWM channel available

G to any PWM channel available

B to any PWM channel available

Cathode to Gnd

Common Anode

R to any PWM channel available G to any PWM channel available

B to any PWM channel available

Anode to 5V

RGB Led Strip

In case of strip out need to switch the the the strip on and off with Mosfet or transistor, I used transistor.I made the driver and it is also given in the schematics.

Step 4: Controlling RGB

To Control The RGB we need to learn how to control a Normal LED Brightness.The Answer is PWM Pulse Width Modulation. It is digital representing Analog signal by varying the duty cycle of the pulse.

In arduino, we use the analog write function to get a PWM wave the function generates a square wave of specified duty cycle the value of which is defined by the user.

In the graphic below, the green lines represent a regular time period. This duration or period is the inverse of the PWM frequency. In other words, with Arduino's PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time)

Step 5: Connection

The Connection the Mode Lamp is SimpleFirst we connect the rgb led or strip .

RGB LED/RGB STRIP

Red to Pin 3 of Arduino

Blue to Pin 5 of Arduino

Green to Pin 6 of Arduino

Anode to 5V If Strip Gnd of driver to gnd of Arduino

HC-05 Connection

Rx to pin 12 of Arduino

Tx to pin 11 of Arduino

vcc to 5v

gnd to gnd

Step 6: Code

#include <SoftwareSerial.h>
#include <Wire.h>//Include libraries: SoftwareSerial & Wire
SoftwareSerial BT(11,12); //Define PIN11 & PIN12 as RX and TX pins
//RGB LED Pins
int PIN_RED = 3;
int PIN_GREEN = 5;
int PIN_BLUE = 6;
//RED LED at Pin 13
int RED_LED = 13;
String RGB = ""; //store RGB code from BT
String RGB_Previous = "255.255.255)"; //preserve previous RGB color for LED switch on/off, default White
String ON = "ON"; //Check if ON command is received
String OFF = "OFF"; //Check if OFF command is received
boolean RGB_Completed = false;
void setup() {
 Serial.begin(9600); //Arduino serial port baud rate:9600
 BT.begin(9600);//My HC-05 module default baud rate is 9600
 RGB.reserve(30);
 pinMode(RED_LED, OUTPUT); 
 //Set pin13 as output for LED, 
 // this LED is on Arduino mini pro, not the RGB LED
}
void loop() {
 // put your main code here, to run repeatedly: 
 
 //Read each character from Serial Port(Bluetooth)
 while(BT.available()){
   char ReadChar = (char)BT.read();
   // Right parentheses ) indicates complet of the string
   if(ReadChar == ')'){
     RGB_Completed = true;
   }else{
      RGB += ReadChar;
   }
 }
 
 //When a command code is received completely with ')' ending character
 if(RGB_Completed){
  //Print out debug info at Serial output window
     Serial.print("RGB:");
     Serial.print(RGB);
     Serial.print("     PreRGB:");
     Serial.println(RGB_Previous);
     
     if(RGB==ON){
         digitalWrite(13,HIGH);
         RGB = RGB_Previous; //We only receive 'ON', so get previous RGB color back to turn LED on
         Light_RGB_LED();          
     }else if(RGB==OFF){
         digitalWrite(13,LOW);
         RGB = "0.0.0)"; //Send OFF string to turn light off
         Light_RGB_LED();
     }else{
         //Turn the color according the color code from Bluetooth Serial Port
         Light_RGB_LED();   
         RGB_Previous = RGB;     
     }
     //Reset RGB String  
     RGB = "";
     RGB_Completed = false;
     
   
 } //end if of check if RGB completed
 
} // end of loop
void Light_RGB_LED(){
 int SP1 = RGB.indexOf('.');
 int SP2 = RGB.indexOf('.', SP1+1);
 int SP3 = RGB.indexOf('.', SP2+1);
 String R = RGB.substring(0, SP1);
 String G = RGB.substring(SP1+1, SP2);
 String B = RGB.substring(SP2+1, SP3);
 //Print out debug info at Serial output window
 Serial.print("R=");
 Serial.println( constrain(R.toInt(),0,255));
 Serial.print("G=");
 Serial.println(constrain(G.toInt(),0,255));
 Serial.print("B=");
 Serial.println( constrain(B.toInt(),0,255));
 //Light up the LED with color code
//**2014-09-21
//Because these RGB LED are common anode (Common positive)
//So we need to take 255 to minus R,G,B value to get correct RGB color code
 analogWrite(PIN_RED,  (R.toInt()));
 analogWrite(PIN_GREEN, (G.toInt()));
 analogWrite(PIN_BLUE,  (B.toInt())); 

If you liked this project support me on Facebook my liking my page, you will aslo be able to talk about your doubts trough the page.

Code

Code snippet #1Plain text
#include <SoftwareSerial.h>
#include <Wire.h>//Include libraries: SoftwareSerial & Wire
SoftwareSerial BT(11,12); //Define PIN11 & PIN12 as RX and TX pins
 
//RGB LED Pins
int PIN_RED = 3;
int PIN_GREEN = 5;
int PIN_BLUE = 6;
//RED LED at Pin 13
int RED_LED = 13;
String RGB = ""; //store RGB code from BT
String RGB_Previous = "255.255.255)"; //preserve previous RGB color for LED switch on/off, default White
String ON = "ON"; //Check if ON command is received
String OFF = "OFF"; //Check if OFF command is received
boolean RGB_Completed = false;
 
void setup() {
  Serial.begin(9600); //Arduino serial port baud rate:9600
  BT.begin(9600);//My HC-05 module default baud rate is 9600
  RGB.reserve(30);
 
  pinMode(RED_LED, OUTPUT); 
  //Set pin13 as output for LED, 
  // this LED is on Arduino mini pro, not the RGB LED
}
 
void loop() {
  // put your main code here, to run repeatedly: 
  
  //Read each character from Serial Port(Bluetooth)
  while(BT.available()){
    char ReadChar = (char)BT.read();
 
    // Right parentheses ) indicates complet of the string
    if(ReadChar == ')'){
      RGB_Completed = true;
    }else{
       RGB += ReadChar;
    }
  }
  
  //When a command code is received completely with ')' ending character
  if(RGB_Completed){
   //Print out debug info at Serial output window
      Serial.print("RGB:");
      Serial.print(RGB);
      Serial.print("     PreRGB:");
      Serial.println(RGB_Previous);
      
      if(RGB==ON){
          digitalWrite(13,HIGH);
          RGB = RGB_Previous; //We only receive 'ON', so get previous RGB color back to turn LED on
          Light_RGB_LED();          
 
      }else if(RGB==OFF){
          digitalWrite(13,LOW);
          RGB = "0.0.0)"; //Send OFF string to turn light off
          Light_RGB_LED();
      }else{
          //Turn the color according the color code from Bluetooth Serial Port
          Light_RGB_LED();   
          RGB_Previous = RGB;     
      }
      //Reset RGB String  
 
      RGB = "";
      RGB_Completed = false;
      
    
  } //end if of check if RGB completed
  
} // end of loop
 
void Light_RGB_LED(){
 
  int SP1 = RGB.indexOf('.');
  int SP2 = RGB.indexOf('.', SP1+1);
  int SP3 = RGB.indexOf('.', SP2+1);
  String R = RGB.substring(0, SP1);
  String G = RGB.substring(SP1+1, SP2);
  String B = RGB.substring(SP2+1, SP3);
 
  //Print out debug info at Serial output window
  Serial.print("R=");
  Serial.println( constrain(R.toInt(),0,255));
  Serial.print("G=");
  Serial.println(constrain(G.toInt(),0,255));
  Serial.print("B=");
  Serial.println( constrain(B.toInt(),0,255));
  //Light up the LED with color code
 
//**2014-09-21
//Because these RGB LED are common anode (Common positive)
//So we need to take 255 to minus R,G,B value to get correct RGB color code
  analogWrite(PIN_RED,  (R.toInt()));
  analogWrite(PIN_GREEN, (G.toInt()));
  analogWrite(PIN_BLUE,  (B.toInt()));
 

Schematics

Connections
Untitled%20sketch%20ss

Comments

Similar projects you might like

Smartphone Controlled Arduino 4WD Robot Car

Project in progress by Andriy Baranov

  • 53,239 views
  • 43 comments
  • 98 respects

Control Your Light Switch with Your Smartphone

Project tutorial by Alasdair Allan

  • 13,535 views
  • 1 comment
  • 33 respects

Bluetooth Controlled Light Switch

Project showcase by Team The Instrumentation Crustaceans

  • 24,995 views
  • 4 comments
  • 27 respects

Controlling LED light intensity using smartphone light senso

Project tutorial by Nikola Travis

  • 1,757 views
  • 0 comments
  • 3 respects

Bluetooth TFS Build LED strobe light

Project tutorial by Jimmy Ramkisoen

  • 3,338 views
  • 0 comments
  • 10 respects
Add projectSign up / Login