This Arduino RGB sequential light generator circuit will generate a smooth flowing red, green blue pattern over the connected RGB LED.
The LED used here is a four pin 30mA RGB LED, common anode type, meaning the common pin for this LED will need to be assigned a continuous positive for the required operations. The LEDs that are specified as common cathode require a continuous negative or ground for the RGB illuminations.
The hardware required for this project:
One Arduino UNO board.
One 220 ohm, 1/4 watt resistor
One RGB, 5mm, 30 mA LED (common anode type)
Link Wires
Soldering iron,
9V adapter AC/DC
The connection details of the proposed RGB LED sequential light circuit using Arduino can be seen in the above diagram.
The connections are pretty easy to implement, just insert the LED leads to the Arduino burg pinouts, switch the the power socket and visualize the RGB LED running the red, green, blue illuminating in a sequential manner.
The code is fully customizable as per the individual preferences and selections,
Code:
Then sketch code for this RGB LED sequential flowing light circuit can be found as given below:
/*
RGB LED color flow
Displays a [fairly] smooth
sequence of colors on an RGB LED
by Jeremy Fonte
Copyright (c) 2012 Jeremy
Fonte. All rights reserved.
This code is released under the
MIT license:
https://opensource.org/licenses/MIT*/
int r = 0;
int g = 0;
int b = 0;
int ri = 1;
int gi = 3;
int bi = 2;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as
an output.
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(9, HIGH);
}
// the loop routine runs over and over again forever:
void loop() {
r = r + ri;
g = g + gi;
b = b + bi;
if(r > 255) {
r = 255;
ri = -1 * random(1, 3);
}
else if(r < 0) {
r = 0;
ri = random(1, 3);
}
if(g > 255) {
g = 255;
gi = -1 * random(1, 3);
}
else if(g < 0) {
g = 0;
gi = random(1, 3);
}
if(b > 255) {
b = 255;
bi = -1 * random(1, 3);
}
else if(b < 0) {
b = 0;
bi = random(1, 3);
}
analogWrite(8, r);
analogWrite(10, g);
analogWrite(11, b);
delay(20);
}
Have Questions? Please Comment below to Solve your Queries! Comments must be Related to the above Topic!!