Tampilkan postingan dengan label Arduino RGB LED. Tampilkan semua postingan

Arduino Control RGB LEDs via Serial Port

-->
Arduino Control RGB LEDs via Serial Port ( USB )

Wiring Diagram for Common Cathode
If you want to use common anode. Must change wiring and edit some Arduino code.
RGB LEDs Output ( PWM output )
Arduino Pin 3 connect to Red LED
Arduino Pin 5 connect to Green LED
Arduino Pin 6 connect to Blue LED

Serial Port to Control
Arduino Pin 0 for Rx
Arduino Pin 1 for Tx
Protocal to Control RGB LEDs
Recevied Text data from serial port( pin 0,1 ) to control RGB Led.

Format Command data
R1 G1 B1 , R2 , G2 , B2 <LF>

value
0-255,0-255,0-255,0,0,0<LF>

Return Data
Data Response : RRGGBB    ( hex value )

Example
For Red colour 
Sent text data to Arduino board      "255,0,0,0,0,0<LF>"    then R LED max value
Data Response : FF0000

For Green colour 
Sent text data to Arduino board      "0,255,0,0,0,0<LF>"    then G LED max value
Data Response : 00FF00

For Blue colour 
Sent text data to Arduino board      "0,0,255,0,0,0<LF>"    then B LED max value
Data Response : 0000FF

Warning
Don't use max value ( 255 ) because voltage output = 3.3 V then LED may damage.
Use value between ( 0-180 ) is fine.

Test Arduino Board with Serial Monitor tool on Arduino Environment Software1.0.3

When you program code to arduino board already.
You can test sent command to control colour RGB LED with Serial Monitor tool.


When Arduino Board 've program already.
It sent response text "Arduino control RGB LEDs Connected OK ( Sent From Arduinno Board )"


When sent command to Arduino Board



Arduino Source Code for Common Cathode

if you want use Common Anode ( need some edit code ) 


//pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;

const int redPin2 = 9;
const int greenPin2 = 10;
const int bluePin2 = 11;

#define REDPIN 3
#define GREENPIN 5
#define BLUEPIN 6

#define FADESPEED 5

void setup() {
// initialize serial:
Serial.begin(9600);

// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

pinMode(redPin2, OUTPUT);
pinMode(greenPin2, OUTPUT);
pinMode(bluePin2, OUTPUT);

Serial.print("Arduino control RGB LEDs Connected OK ( Sent From Arduinno Board )");
Serial.print('\n');
}

void loop() {

// if there's any serial available, read it:
while (Serial.available() > 0) {
 
 // look for the next valid integer in the incoming serial stream:
 int red = Serial.parseInt();
 // do it again:
 int green = Serial.parseInt();
 // do it again:
 int blue = Serial.parseInt();

 int red2 = Serial.parseInt();
 // do it again:
 int green2 = Serial.parseInt();
 // do it again:
 int blue2 = Serial.parseInt();

 // look for the newline. That's the end of your
 // sentence:
 if (Serial.read() == '\n') {
           
   // constrain the values to 0 - 255 and invert
   // if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
  
   // This is for COMMON ANODE
   //red = 255 - constrain(red, 0, 255);
   //green = 255 - constrain(green, 0, 255);
   //blue = 255 - constrain(blue, 0, 255);
  
   red = constrain(red, 0, 255);
   green = constrain(green, 0, 255);
   blue = constrain(blue, 0, 255);
  
   red2 = constrain(red2, 0, 255);
   green2 = constrain(green2, 0, 255);
   blue2 = constrain(blue2, 0, 255);

   // fade the red, green, and blue legs of the LED:
   analogWrite(redPin, red);
   analogWrite(greenPin, green);
   analogWrite(bluePin, blue);
  
   analogWrite(redPin2, red2);
   analogWrite(greenPin2, green2);
   analogWrite(bluePin2, blue2);

   // print the three numbers in one string as hexadecimal:
    Serial.print("Data Response : ");
   Serial.print(red, HEX);
   Serial.print(green, HEX);
   Serial.println(blue, HEX);
 }
}

}


Download Arduino control RGB LEDs Code
( For USB Version and Bluetooth Version )
http://www.digital2u.net/files/ArduinoControlRGBLed/controlRGBLed.ino -->



Android App to Control Arduino RGB LEDs
Android app on Google Play
https://play.google.com/store/apps/details?id=arduino.control.rgbleds

Arduino control RGB LEDs

Arduino control RGB LEDs

Hardware
Arduino compatible Board from ETT model ET-BASE-AVR-EASY328 more info

RGB LEDs model SPNovaLED NMRTB-USD-AAB+ADE+Y2Z1-1 ( Dominant Semiconductors)


RGB LED spec
SPNovaLEDTM
Featuring a staggering brilliance and significant flux output, the SPNovaLED™ showcases the latest technological advent in this range. With its extremely high level of brightness and the ultra low high profile, which is only 1.5 mm are highly suitable for both conventional lighting and specialized application such as automotive signal lights, traffic lights, channel lights, tube lights and garden lights among others.

Features:
> Super high brightness surface mount LED.
> High flux output.
> 125° viewing angle.
> Compact package outline (LxWxH) of 6.0 x 6.0 x 1.5mm.
> Ultra low height profile - 1.5 mm.
> Designed for high current drive; typically 250 mA.
> Low junction-to-solder point thermal resistance; RTH js = 50 K/W.
> Qualified according to JEDEC moisture sensitivity Level 2.
> Compatible to IR reflow soldering.
> Environmental friendly; RoHS compliance.

Applications:
> Signage: full colour display video notice board, signage, special effect lighting.
> Lighting: architecture lighting, general lighting, garden light, channel light.

Download RGB LEDs Datasheet

Arduino code

/*
 Fading
 This example shows how to fade an LED using the analogWrite() function.
 */
#define REDPIN 9             // LED connected to digital pin 9
#define GREENPIN 10    // LED connected to digital pin 10
#define BLUEPIN 11        // LED connected to digital pin 11

#define FADESPEED 5

void setup()  {
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
}

void loop()  {
   int r, g, b;
 
  for (r = 0; r < 120; r++) {     // fade from blue to violet
    analogWrite(REDPIN, r);
    delay(FADESPEED);
  }
 
  for (b = 120; b > 0; b--) {      // fade from violet to red
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  }
  for (g = 0; g < 120; g++) {   // fade from red to yellow
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  }
  for (r = 120; r > 0; r--) {        // fade from yellow to green
    analogWrite(REDPIN, r);
    delay(FADESPEED);
  }
  for (b = 0; b < 120; b++) {    // fade from green to teal
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  }
  for (g = 120; g > 0; g--) {      // fade from teal to blue
    analogWrite(GREENPIN, g);
    delay(FADESPEED);                           
  }
}