Home Code Arduino and keyes RGB Led module example

Arduino and keyes RGB Led module example

by shedboy71

This example was for an RGB Led display I saw. It contains 8 led's, 3 control lines for the red, green and blue and also requires a 5v connection. The LEDs are common cathode types so a low (0v) switches them on and a high (5v) switches them off.

So a lot of pins required for an Arduino Uno out of the box. Its quite a niche little product but if you wanted a bar of RGB led's this could be an effective solution

Here is a picture of the module

Connection

Vcc – Arduino 5v

D0 – D7 -> Connect these to Arduino pins 2 to 9

R, G, B -> Connect these to Arduino pins 10 to 12

Code

Simple example that cycles through the red, green and blue colours. You could add more colours, have different effects and so on.

[codesyntax lang=”cpp”]

void setup()
{
  //all pins are outputs and we are using 2 to 13
  for (int x =2;x<13;x++)
  {
    pinMode(x,OUTPUT);
    digitalWrite(x,HIGH);
  }
}

void loop()
{
   blue();
   cycle(); 
   green();
   cycle();
   red();
   cycle();
}

void blue()
{
  digitalWrite(12,LOW);
}

void green()
{
  digitalWrite(11,LOW);
}

void red()
{
  digitalWrite(10,LOW);
}


void cycle()
{
  for(int x=2;x<10;x++)
  {
    digitalWrite(x,LOW);
    delay(500);
    digitalWrite(x,HIGH);
  }
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);
  digitalWrite(12,HIGH);
}

[/codesyntax]

 

Links

The module comes in at the $5 mark
Full Color LED Module / SCM light water

Share

You may also like

Leave a Comment