0% found this document useful (0 votes)
77 views

Experiment 2: Red Green Blue (RGB) LED: The Common Cathode

The document describes an experiment using an RGB LED. It explains that an RGB LED contains red, green, and blue LEDs and can display over 16 million colors. It then discusses the two types of RGB LED configurations - common anode and common cathode - and shows the circuit connections. The document also includes Arduino code to control the RGB LED and cycle through different colors.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Experiment 2: Red Green Blue (RGB) LED: The Common Cathode

The document describes an experiment using an RGB LED. It explains that an RGB LED contains red, green, and blue LEDs and can display over 16 million colors. It then discusses the two types of RGB LED configurations - common anode and common cathode - and shows the circuit connections. The document also includes Arduino code to control the RGB LED and cycle through different colors.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

16/10/2019

Experiment 2: Red Green Blue (RGB) LED


RGB LED is a single LED that contains 3 LEDs:
red, green and blue. It can shine in over 16 million What is RGB LED
colons and is as easy to use as normal LEDs.
There are of two types.
In this configuration, the longest leg will be connected to
VCC (5V) and the rest of them to the Arduino pins. It The common anode
shines at LOW states of the pins
In this configuration , the longest leg of the LED will be
connected to ground (GND) and the other 3 legs to 3 of the
Arduino pins. It shines at HIGH states of the pins.

The common cathode

10/16/2019 1

Circuit Connection for the RGB LED

Components Needed

Circuit Connections

10/16/2019 2

1
16/10/2019

Circuit Connection for the RGB LED

10/16/2019 3

The Code
Declaration int red_light_pin= 11;
int green_light_pin = 10;
int blue_light_pin = 9;

void setup() {
pinMode(red_light_pin, OUTPUT);
pinMode(green_light_pin, OUTPUT); Void Setup
pinMode(blue_light_pin, OUTPUT);
void loop() {
}
RGB_color(255, 0, 0); // Red
delay(1000);
RGB_color(0, 255, 0); // Green
delay(1000);
RGB_color(0, 0, 255); // Blue
Void Loop delay(1000);
RGB_color(255, 255, 125); // Raspberry
delay(1000);
RGB_color(0, 255, 255); // Cyan
delay(1000);
RGB_color(255, 0, 255); // Magenta
delay(1000);
RGB_color(255, 255, 0); // Yellow
delay(1000);
RGB_color(255, 255, 255); // White
delay(1000);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
10/16/2019 }
analogWrite(blue_light_pin, blue_light_value);
4

2
16/10/2019

10/16/2019 DEPARTMENT OF COMPUTER AND COMMUNICATIONS SYSTEMS ENGINEERING , UPM 5

int red_light_pin= 11;
int green_light_pin = 10;
int blue_light_pin = 9;
void setup() {
pinMode(red_light_pin, OUTPUT); void setup() {
pinMode(green_light_pin, OUTPUT); pinMode(9, OUTPUT);
pinMode(blue_light_pin, OUTPUT); pinMode(10, OUTPUT);
} pinMode(11, OUTPUT);
void loop() {
RGB_color(255, 0, 0); // Red }
delay(1000);
RGB_color(0, 255, 0); // Green void loop() {
delay(1000); for(int r = 0; r < 255; r++){
RGB_color(0, 0, 255); // Blue analogWrite(9, r);
delay(1000); delay(10);
RGB_color(255, 255, 125); // Raspberry }
delay(1000); for(int g = 0; g < 255; g++){
RGB_color(0, 255, 255); // Cyan analogWrite(10, g);
delay(1000); delay(10);
RGB_color(255, 0, 255); // Magenta }
delay(1000); for(int b = 0; b < 255; b++){
RGB_color(255, 255, 0); // Yellow analogWrite(11, b);
delay(1000); delay(10);
RGB_color(255, 255, 255); // White }
delay(1000); }
}
void RGB_color(int red_light_value, int green_light_value, int
blue_light_value)
{
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
analogWrite(blue_light_pin, blue_light_value);
}
CROSS LAYER FRAMEWORK FOR COGNITIVE RADIO 
16/10/2019 6
WIRELESS SENSOR NETWORK

You might also like