top of page

RGB LED Interface with PIC16F877A micro-controller

By Bernice Zuiya

Introduction

                RGB stands for Red Green and Blue color, with this LED (Light emitting Diode) it maybe possible to obtain a large number of color from the combination of green, blue and red. In this instructable I will simply give a brief explanation of how you can Interface an RGB LED with a PIC16F877A controller using PWM module.

RGB LED

R-G-B 

Working

              

              What I am going to tell you here is how an RGB LED can directly be connected to a micro-controller, basically comparing to what we has done in the previous project of blinking an LED using a micro-controller here is somehow different because there a resistance were used in series with the LED to limitate the current flowing in the LED but here we are not going to use a resitance in series bu the p terminal of the RGB LED will be directly connected to one PWM pin on PORTC of the controller and n terminal to ground. The main principle of operation of an RGB LED is as we know the pulse width modulation's output can also be measured as an analog signal, so for that each quantity correcpond to a color. It means that for example if the PWM pin give 2.7 Volt it may correspond to chocolate color; the code show below is written in mikroC compiler for PIC where it basically use the PWM library and for this project we are generating the PWM with a frequency equal to 5 KHz or 5000 Hz read more about PWM Here.

Circuit Diagram

                        The circuit diagram show below show how an RGB LED can be connected to one PWM pin (CPP1) of the PIC16F877A where I did put a resistor in series with the LED compared to what we did in LED blinking project. 

Code:

Download the full project here

void main() 
{
TRISC=0X7C;        // the two first Pins of PORTC in OUTPUT and all remaining as Imput
PORTC=0X00;        // All pins of PORTC in Low State (0)
PWM1_Init(5000);   // Setting PWM at 5000Hz
PWM1_Start();      // Start PWM Module
   for(;;)
     {
       unsigned int i;
       for(i=0;i<255;i++){
              PWM1_Set_Duty(i);  // the Duty cycle change with the increasing of the of i'value
              delay_ms(50);    // Delay 1 second.
              }
       for(i=255;i<0;i--){
          PWM1_Set_Duty(i);  // the Duty cycle change with the Decrementing of the of i'value
          delay_ms(50);    // Delay 1 second.
         }
     }
}

bottom of page