[Project 7] – RGB LED Control With Button

In this project we will make RGB LED Control With Button. To understand this project  you should know working prencible RGB (RGB: Red Green Blue; LED: Light Emitting Diode ) I will use arduino uno in the circuit design program. I use usually arduino mega 2560.  You can use the other arduino cards. This project for beginners. Good Luck.

rgb_led_control_with_button_bbc

Schema:


 rgb_led_control_with_button_schema

 

RGB LED Pins:


rgb_led_picture

Materials:


Arduino UNO / Other Arduino Cards        x 1
Breadboard                               x 1
330 ohm resistor                         x 3 
10 kohm resistor                         x 1
RGB LED                                  x 1
Button                                   x 1
Jumper Cable

 

Program:

//  letsarduino.com
//  [Project 7] - RGB LED Control With Button

const int BlueLed=10;
const int GreenLed=9;
const int RedLed=8;
const int button=7;

boolean beforeCase=LOW;
boolean nowCase=LOW;

int ledMode=0;

  void setup()
 {
 pinMode(BlueLed,OUTPUT);
 pinMode(GreenLed,OUTPUT);
 pinMode(RedLed,OUTPUT);
 pinMode(button,INPUT);
 }

   boolean buttonControl(boolean now)
  {
   boolean presentBtn = digitalRead(button);
   if(now!=presentBtn)
  {
   delay(5);
   presentBtn=digitalRead(button);
  }
   return presentBtn;
  }

    void rgbSet(int colour)
   {
 
       if(colour==1)
   {
     digitalWrite(RedLed,LOW); 
     digitalWrite(GreenLed,HIGH); 
     digitalWrite(BlueLed,HIGH);  
 }
       else if(colour==2)
{
     digitalWrite(RedLed,HIGH); 
     digitalWrite(GreenLed,LOW); 
     digitalWrite(BlueLed,HIGH);
}
       else if(colour==3)
{
     digitalWrite(RedLed,HIGH); 
     digitalWrite(GreenLed,HIGH); 
     digitalWrite(BlueLed,LOW);
}
       else if(colour==4)
{
     analogWrite(RedLed,150);   
     analogWrite(GreenLed,0); 
     analogWrite(BlueLed,150);  
}
       else if(colour==5)
{
     analogWrite(RedLed,0);   
     analogWrite(GreenLed,50); 
     analogWrite(BlueLed,50);  
}
}
         void loop()
      {
         nowCase=buttonControl(beforeCase);
         if(beforeCase==LOW && nowCase==HIGH)
      {
         ledMode++;
      }
         beforeCase=nowCase;
         if(ledMode==6)
         ledMode=0;
   
         rgbSet(ledMode);

}


 

Project Related Images:


 

rgb led buttonrgb led button redrgb led button blue



 

You may also like...