How to use a 4 pin RGB LED module with Arduino | 4 pin | Tutorial

RGB Module - RGB LED module is actually of two types common cathode and common cathode and we give PWM (pulse width modulation) in order to get different colors of different intensity. In this experiment, we will see how we can interface or use an RGB LED module with 4 pins and will also control it.

Apparatus Required: one RGB LED module, breadboard, several connecting wires.

Procedure: 

  1. Connect the RGB module with the breadboard. 
  2. Connect the red wire (red color wire not mandatory) to the pin labeled 'r'. 
  3. Now connect the green wire to the pin labeled 'g'. 
  4. Similarly, connect the blue wire to the pin labeled 'b'. 
  5. Let us now connect the 4th pin to the GND and with this, the connection is over. 

Arduino Sketch:



int redpin = 5; // select the pin for the red LED
int bluepin =3; // select the pin for the  blue LED
int greenpin =7; // select the pin for the green LED

int val;

void setup() {
  pinMode(redpin, OUTPUT);
  pinMode(bluepin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  for(val = 255; val > 0; val--)
  {
    analogWrite(5, val);
    analogWrite(3, 255 - val);
    analogWrite(7, 128 - val);

    Serial.println(val, DEC);
    delay(5); 
  }
  for(val = 0; val < 255; val++)
  {
    analogWrite(5, val);
    analogWrite(3, 255 - val);
    analogWrite(7, 128 - val);
    
    Serial.println(val, DEC);
    delay(5); 
  }

For live demonstration visit: https://youtu.be/hj7aYin5QmM

Thank You!

Post a Comment

0 Comments