The article discusses a simple,Arduino red, green, blue LED light effect generator circuit in a random pattern.
In one of the earlier posts we came across a similar RGB LED effect generator circuit using Arduino which was programmed to produce the effect in a flowing sequential manner, whereas here the set up can be expected to generate randomly changing RGB LED effect.
Hardware Required
What you will need for making this system:
1) An Arduino Board
2) A RGB LED
3) A 220 Ohm 1/4 watt resistor
4) A 9V AC to DC adapter Unit
Once you have acquired the above units, it's just about programming the Arduino IC with the following sample code, and subsequently integrating the LED, resistor and the power supply with the Arduino board as shown below:
How to Wire Arduino with LED
The set up appears to be exactly similar to our previous RGB Arduino project, yes it is so, except the program which has been now changed for generating a random RGB LED light effect rather than the earlier sequentially flowing RGB color effect.
The LED used here is a 5mm 30 mA RGB LED, which is supposed to produce pretty high illumination, however for operating more nummer of LEDs from the same set up you may have to use transistor drivers across the pin#8, 10, 11, which may allow you you to add many RGB LEDs in parallel with the proposed random color effect.
The Code
The sample code for the above explained Arduino RGB color generator circuit is furnished below:
*
RGB LED random
color
Displays a
sequence of random 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
*///one variable for each of red, green, and blue
int r = 0;
int g = 0;
int b = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize
the four digital pins as outputs.
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 = random(0,
255);
g = random(0,
255);
b = random(0,
255);
analogWrite(8,
r);
analogWrite(10, g);
analogWrite(11, b);
delay(1000);
}