0% found this document useful (0 votes)
23 views4 pages

IOT Lab Experiment No.2

Iot

Uploaded by

rei0zlitch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

IOT Lab Experiment No.2

Iot

Uploaded by

rei0zlitch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical 2

Interfacing the RGB LED with the Arduino


Introduction: There are actually two types of RGB LED’s; the common
cathode one and the common anode one. In the common cathode RGB led, the
cathode of all the LED’s is common and we give PWM signals to the anode
of LED’s while in the common anode RGB led, the anode of all the LED’s is
common and we give PWM signals to the cathode of LED’s. Inside the RGB
led, there are three more LED’s. So, by changing the brightness of these
LED’s, we can obtain many other colors. To change brightness of RGB led,
we can use the PWM pins of Arduino. The PWM pins will give signal different
duty cycles to the RGB led to obtain different colors.
Hardware Required:

Component Name Quantity

Arduino UNO 1

RGB LED 1

220Ω/330Ω resistor 3

USB Cable 1

Breadboard 1

Jumper wires several

Connection Diagram:
Steps of working
1. Insert the RGB LED into your breadboard and connect its cathode pin
to the GND of the Arduino.
2. Insert the LED into the breadboard. Attach Red pin to pin 8, Green pin
to pin 9 and Blue pin to pin 10 of the Arduino via the 220-ohm resistor,
and the negative leg to GND.
3. Upload the code as given below.
4. Observe the changes in the color of the RGB LED.

The Sketch
This sketch works by setting pinsD8, D9, D10 as for the different legs of RGB
LED. After that the run a loop that continually reads the value from the pins
and sends that value as voltage to the LED. The voltage value is between 0–5
volts, and the blinking of the LED will vary accordingly.
/************RGB LED Blink*******/
void setup() {
// put your setup code here, to run once:
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite (8,HIGH);
digitalWrite (10,LOW);
delay(1000);
digitalWrite (9,HIGH);
digitalWrite (8,LOW);
delay(1000);
digitalWrite (10,HIGH);
digitalWrite (9,LOW);
delay(1000);
}

Observations:

Sr. No. Time(ms) Color of LED

You might also like