IOT Lab Experiment No.2
IOT Lab Experiment No.2
Arduino UNO 1
RGB LED 1
220Ω/330Ω resistor 3
USB Cable 1
Breadboard 1
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: