5% OFF Over $19, Code: Elephant5; 10% OFF Over $59, Code: Elephant10



Arduino UNO R3/MEGA 2560 R3 Project 9: RGB LED

Posted by Fiona Su on

Introduction

Tricolor principle to display various colors;
PWM controlling ports to display full color;
Can be driven directly by Arduino PWM interfaces.

RGB LED

Hardware List

  • Arduino controller × 1
  • USB cable × 1
  • Full-color LED module × 1
  • Resistor *3
  • Breadboard jumper wire*5

Video Tutorial

Connection

Connection for REV4:

thumb

Connection for 2560 R3:

thumb

Sample Code:

int redpin = 11; //select the pin for the red LED
int bluepin =10; // select the pin for the blue LED
int greenpin =9;// select the pin for the green LED

int val;

void setup() {
  pinMode(redpin, OUTPUT);
  pinMode(bluepin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  Serial.begin(9600);
}

void loop() 
{
for(val=255; val>0; val--)
  {
   analogWrite(11, val);
   analogWrite(10, 255-val);
   analogWrite(9, 128-val);
   delay(1); 
  }
for(val=0; val<255; val++)
  {
   analogWrite(11, val);
   analogWrite(10, 255-val);
   analogWrite(9, 128-val);
   delay(1); 
  }
 Serial.println(val, DEC);
}

Result

Directly copy the above code into arduino IDE, and click upload thumb, wait for a few seconds, you can see a full-color LED.

thumb 

All Tutorial

Buy 

0 comments

Leave a comment

Please note, comments must be approved before they are published