Skip to main content

RGB Led Fading effect using Arduino

RGB Led Arduino
The RGB LED can emit different colors by mixing the 3 basic colors red, green and blue. So, it actually consists of 3 separate red, green and blue LEDs, packaged in one box. This is why it has 4 leads, one for each of the 3 colors and a common cathode or anode depending on the type of RGB LED. In this tutorial I will use a common cathode.
Components required for this Project :
  • RGB Led - Buy
  • Arduino Uno - Buy
  • Breadboard and Jumpers - Buy

Circuit Diagram

RGB Led and Arduino Circuit Digram

Above is the circuit diagram of the RGB Led and Arduino Uno,
As you can see the ground pin  of the RGB LED is connected to the ground of the Arduino and other 3 pins of RGB Led are connected to the PWM Pins of Arduino Uno (9, 10, 11).

Code



int ledPin = 9; 
int ledPin1 = 10;
int ledPin2 = 11;

void setup() {}
void loop()
{
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) 
  {
    analogWrite(ledPin, fadeValue);
    delay(20);
  }
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) 
  {
    analogWrite(ledPin, fadeValue);
    delay(20);
  }
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) 
  {
    analogWrite(ledPin1, fadeValue);
    delay(20);
  }
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) 
  {
    analogWrite(ledPin1, fadeValue);
    delay(20);
  }
    for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) 
    {
    analogWrite(ledPin2, fadeValue);
    delay(20);
    }
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) 
  {
    analogWrite(ledPin2, fadeValue);
    delay(20);
  }
    for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) 
    { 
    analogWrite(ledPin, fadeValue);
    analogWrite(ledPin1, fadeValue);
    delay(20);
    }
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) 
  {
    analogWrite(ledPin, fadeValue);
     analogWrite(ledPin1, fadeValue);
    delay(20);
  }
     for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) 
     {
    analogWrite(ledPin, fadeValue);
    analogWrite(ledPin2, fadeValue);
    delay(20);
    }
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) 
  {
     analogWrite(ledPin, fadeValue);
     analogWrite(ledPin2, fadeValue);
     delay(20);
  }
   for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) 
   {
    analogWrite(ledPin1, fadeValue);
    analogWrite(ledPin2, fadeValue);
    delay(20);
  }
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) 
  {
     analogWrite(ledPin1, fadeValue);
     analogWrite(ledPin2, fadeValue);
     delay(20);
  }
   for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) 
   {
      analogWrite(ledPin, fadeValue);
      analogWrite(ledPin1, fadeValue);
      analogWrite(ledPin2, fadeValue);
      delay(20);
  }
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) 
  {
     analogWrite(ledPin, fadeValue);
     analogWrite(ledPin1, fadeValue);
     analogWrite(ledPin2, fadeValue);
     delay(20);
  }
}

The code has used the fundamental properties of mixing RGB Colors and Producing different Colors.
Here is the table of RGB color mixing.
RGB Led Mixing Colors Table

By changing the value in the variable fadevalue we can create various colors by simultaneously turning ON leds together.

Hope you Like This post. 

Comments

Popular posts from this blog

7400 - Quad Two Input NAND Gate

7400 - Quad Two Input NAND Gate 74LS00 is part of the 74XXYY IC series. 74xxyy integrated circuits are logical gates of digital electronics. The 74LS00 IC has four NAND gates(NAND Gate is the combination of AND and NOT Gate). In addition, each door has two entrances. Hence the name QUAD TWO INPUT NAND GATE.     Pin Diagram of 7400 IC 74LS00 is a 14-pin device. The chip is available in different packages and is chosen according to the needs.  The description of each pin is given below. Pin Number Description 1 A1-INPUT1 of GATE 1 2 B1-INPUT2 of GATE 1 3 Y1-OUTPUT of GATE1 4 A2-INPUT1 of GATE 2 5 B2-INPUT2 of GATE 2 6 Y2-OUTPUT of GATE2 9 A3-INPUT1 of GATE 3 10 B3-INPUT2 of GATE 3 8 Y3-OUTPUT of GATE3 12 A4-INPUT1 of GATE 4 13 B4-INPUT2 of GATE 4 11 Y4-OUTPUT of GATE4 7 GND- Connected to ground 14 VCC-Connected to positive voltage to provide smdksmkm power to all four gates ...

8051 Microcontroller

The Intel 8051 microcontroller is one of the most popular general purpose microcontrollers in use today. The success of the Intel 8051 spawned a number of clones, which are collectively referred to as the MCS-51 family of microcontrollers, which includes chips from vendors such as Atmel, Philips, Infineon, and Texas Instruments. The Intel 8051 is an 8-bit microcontroller which means that most available operations are limited to 8 bits. There are 3 basic "sizes" of the 8051: Short, Standard, and Extended. The Short and Standard chips are often available in DIP (dual in-line package) form, but the Extended 8051 models often have a different form factor, and are not "drop-in compatible". All these things are called 8051 because they can all be programmed using 8051 assembly language, and they all share certain features (although the different models all have their own special features). Some of the features that have made the 8051 popular are: 4 KB on chip...

Bluetooth Module HC-05

Bluetooth Module HC-05 Introduction Bluetooth Module HC-05 Hardware Features Software Features Pin Description How to connect HC-05 Bluetooth module with Arduino Uno? Hardware and Software Required Hardware Connections Program for HC-05 Bluetooth Module Introduction HC‐05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module,designed for transparent wireless serial connection setup.The HC-05 Bluetooth Module can be used in a Master or Slave configuration, making it a great solution for wireless communication.This serial port bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio transceiver and baseband. It uses CSR Bluecore 04‐External single chip Rluetooth system with CMOS technology and with AFH (Adaptive Frequency Hopping Feature). Bluetooth Module HC-05 The Bluetooth module HC-05 is a MASTER/SLAVE module.By default the factory setting is SLAVE.The Role of the module (Maste...