Arduino and multi-color LED example

This is part of a 37-1 sensor kit, this was a multi-colour LED that was in the kit. NOt much documentation but I wired it up as follows

I – GND
R – Pin 4
G – Pin 5
B – Pin 6

multi color led sensor

Code

Cycle through the LED colours

int red = 4;
int green = 5;
int blue = 6;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);pinMode(red, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(red, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
digitalWrite(green, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(green, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
digitalWrite(blue, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(blue, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

 

Switch them all on at the same time

int red = 4;
int green = 5;
int blue = 6;

// the setup routine runs once when you press reset:
void setup()
{
// initialize the digital pin as an output.
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(red, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(green, HIGH); // turn the LED on (HIGH is the voltage level) // wait for a second
digitalWrite(blue, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(red, LOW); // turn the LED off by making the voltage LOW
digitalWrite(green, LOW); // turn the LED off by making the voltage LOW
digitalWrite(blue, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

 

Links

Here are links to the sensor kit

Ultimate 37 in 1 Sensor Modules Kit for Arduino from Amazon UK
Ultimate 37 in 1 Sensor Modules Kit for Arduino from Amazon US

Related posts

VEML6070 ultraviolet light sensor on an Arduino

Programming an Attiny44 using an Arduino

Programming an Attiny85 using an Arduino