Introduction: Arduino and RGB LED Module - Three Examples

Hello!

Untitled 1

This is small tutorial how to use RGB modulewithArduino.

Please check my video to get more information and to se how RGB module work:

https://www.youtube.com/watch?v=5fnNmfkPh5E

I prepered three simple examples to work with!

For this example you will need:

  • Arduino board
  • RGB module
  • Pushbutton
  • breadboard
  • potentiometer (variable resistor)
  • wires

Step 1: Example 1.

This is the simplest example, in this example colors will be changed automatically. Speed of colour changing can be adjusted in code.

How to connect module to arduino?

This module have have 4 pins.

- , R, G, B


Connect - to GND on Arduino

connect R to PIN 9 on Arduino

connect G to PIN 10 on Arduino

connect B to PIN 11 on Arduino

NOTE!

This module has resistors included so you don't need to connect them. If you have RGB LED without resistors or module without resistors, don't forget to use them to limit current.

Upload this code to your Arduino board. Speed can be changed by changing timeChange variable in code:

Code:

void setup() {
pinMode(9,OUTPUT);

pinMode(10,OUTPUT);

pinMode(11,OUTPUT);

}

int timeChange=500;

void loop()

{

digitalWrite(9,1); // red turn ON

delay(timeChange);

digitalWrite(9,0); //red turn OFF

digitalWrite(10,1); //green turn ON

delay(timeChange);

digitalWrite(10,0); //green turn OFF

digitalWrite(11,1); //blue turn ON

delay(timeChange);

digitalWrite(11,0); //blue turn OFF

}

Step 2: Example 2.

In this simple example you can change colour by presing push-button.

Connections

Module

  • Connect - to GND on Arduino
  • connect R to PIN 9 on Arduino
  • connect G to PIN 10 on Arduino
  • connect B to PIN 11 on Arduino

Push-Button

  • Connect one side of pushButton to GND on Arduino
  • Connect other side of pushButton to PIN 12 on Arduino

Upload this code and now you can chose colour that you want.

Code:

void setup() {
pinMode(12,INPUT_PULLUP);

pinMode(9,OUTPUT);

pinMode(10,OUTPUT);

pinMode(11,OUTPUT);

}

int mode=1;

int presed=55;

int sto=0;

void loop()

{

presed=digitalRead(12);

if(presed==0)

{

if(sto==0)

{

sto=1;

mode=mode+1;

} }

else

{ sto=0; }

if(mode>=4)

mode=1;

if(mode==1)

{ digitalWrite(9,1);

digitalWrite(10,0);

digitalWrite(11,0); }

if(mode==2)

{ digitalWrite(9,0);

digitalWrite(10,1);

digitalWrite(11,0); }

if(mode==3)

{ digitalWrite(9,0);

digitalWrite(10,0);

digitalWrite(11,1);

} delay(50); }

Step 3: Example 3 - Ajdusting Intensity of Each Colour

In the last example, we used a push button to change colours.

In this example, we will add the potentiometer (variable resistor) to our project. Push button will still be used for cycling thru colours and potentiometer will be used to change the intensity of each colour. So we can mix colours and create new ones.

You can check how its work in this video:

https://www.youtube.com/watch?v=5fnNmfkPh5E

You will need 10K potentiometer for this project.

Conecting : (Module and pushbutton are already connected so we need only connect potentiometer).

Potentiometer have three wires. Conect your pol like this.

So:

First pin on POT needs to be connected to 5V on Arduino

Second pin on POT needs to be connected to A0 on Arduino

Third needs to be connected on GND on Arduino

Code:

Download and upload this code and have fun!

https://drive.google.com/open?id=0BzYhjTpbP20DdGh5clJPdUJaS2s