Instructables

6 button RGB controller.

Featured
Picture of 6 button RGB controller.
IMG_2828.jpg
IMG_2829.jpg
In this instructable we will learn how to use 6 buttons to control the color of an RGB LED with the use of an Arduino Micro Controller. This is a fun and easy little project that should take you no more then 20 minutes to finish. 


Materials Needed:
  • Arduino
  • Beadboard
  • Jumper Wires
  • 6x push buttons
  • RGB LED with common Anode
  • 220 Ohm Resistor
  • 470 Ohm Resistor
  • 1K Ohm Resistor

 
Remove these adsRemove these ads by Signing Up

Step 1: Connecting an RGB LED

IMG_2840.jpg
IMG_2841.jpg
IMG_2848.jpg
Before we connect the LED to the breadboard we first need to identify the Anode and Cathodes. If you pick up your LED at a retailer there should be a diagram on the package indicating the Anode and Cathode as well as which pin goes to which color. As with every LED the longest pin is the Anode. On my LED the pins are arranged as Red Cathode, Anode, Blue Cathode, and Green Cathode. We can now plug the LED into the breadboard. 

Another important fact about LEDs is the Anode always has the voltage going into it and the Cathode goes to ground. So we will want to place a jumper from the Anode to the 5V rail on the breadboard. Next we need to add resistors to the cathodes. Resistors are needed to limit the current flowing to the LEDs. Since we are connecting the LED to 5V we need to limit the current going into it otherwise we could burn out the LED. If we go from one cathode to the next plugin the same resistor between it and ground we can see that the different colors are not shining at the same intercity. In the pictures i used a 220 Ohm resistor to demonstrate the differences in brightness. Its easy to see that the Red is the dimmest. The difference in the Blue and Green are hard to tell in the picture but the green is actually brighter. So we will use a 220 Ohm Resistor on the Red, 470 Ohm on the Blue and a 1k Ohm on the Green. We want to plug them in with the LED and on the other side of the board. Finally we will connect some longer jumper wires to the resistors. 

Now we will take the wire on the Red LED and connect it to pin 9 on the Arduino. We put the Blue LED wire on pin 10 and the Green LED wire on Pin 11.

Well done ! I was looking for a way to add fade values and this explains things very well. Many thanks for for sharing !
Build_it_Bob
olierko2 years ago
Hi Guys

I love the idea of this project and have already got an idea for where i want to use it. However im running into a problem that is really confusing me. I have laid out the wiring exactly as has been illustrated but i only seem to be able to get the Red LED to illuminate, and not even that bright. The other confusing issue is that this only works when i change the power input from the 5v supply to the 3.3v. So why am i only getting a response when i give it less power. Needless to say im very new but after days of racking my brain i thought it about time to ask. My resistors are all 150Ohm which i coud possibly blame for the green and blue not working but why will it only work on a lower voltage?

Thanks in Advance

Oliver
mpilchfamily (author)  olierko2 years ago
How about posting a picture of your wiring. Maybe we can find what is going on with your setup. 

Using a 150 Ohm resistor on each of the color in the RGB isn't going to prevent that color from lighting. If anything it will allow too much current to flow through the LED and either make the light very bright or burn out the LED. 

Be sure to double and triple check everything. This project was a long time coming and with through a couple of different iterations before it ended up here. I started with 3 separate LEDs then eventually purchased a couple of RGB LEDs. I could swear i had a link to the old Arduino Forums where i was originally documenting and working through all my coding and hardware issues. Well here's the link. You'll see it was quite frustrating at first making the transition from 3 individual LEDS (that where controlled through there Cathodes) to a common Anode RGB and the headaches that followed readjusting the code to work. 
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1263501476/0

DOuble check your RGB and make sure you have a common Anode RGB not a common Cathode. Otherwise the sketch isn't going to work and will need to be rewritten to accommodate the common Cathode. To put it simply the logic of the program would need to be reversed. 
WOW It works and its amazing!

Firstly thanks for making me aware that there are both common anode and cathode RGBs. This was something i had no idea about. So all it took to get it running was to connect the common to ground as opposed to the voltage. Strangely it only works with two leads running to ground. The push buttons that i have connected to ground are sending the signals and wont change values without it connected this way while the common cathode is finishing the circuit. Is this a correct analysis?This seems rather odd to me and i discovered this only as an attempt at reversing the common to Cathode instead of Anode. Hope you can see through the excess of wire.

Thank you so much

Now to discover how to connect more RGB's to make an awesome mood light for my party camper.
IMAG0884.jpgIMAG0885.jpgIMAG0886.jpg
mpilchfamily (author)  olierko2 years ago
You can connect the buttons however you want its just a matter of how you treat them in your code. If you follow my code then the buttons are tied to ground and your using the internal pull up resistors on the Arduino. So the default setting for the button pins is high. When a button is pushed it is pulled low, the arduino sees the change and executes the appropriate code. If you wanted to wire the buttons to the +5v then you would need to do it through a set of resistors. Then you would need to declare the button pins as low. They are pulled to high when a button is pressed. In this configuration you are not able to use the internal resistors and have to use your own to help put a load on the line to pull the pin to a high state.

Since you are working with a common cathode RGB you need to reverse the logic. So lets look at the buttons for the red side of the LED.

So the red buttons go from this:
if(buttonstate == LOW && fadered >0 && button[x] == 2)
    {
      // if button is pressed increase brightness by 5
      fadered -=5;
      analogWrite(ledpin[0], fadered);  // lights LED at current brightness level
      delay(250);  // allows time so button won't be detected multiple times
    }
  
    if(buttonstate == LOW && fadered < 255 && button[x] == 3)
    {
      // if button is pressed decrease brightness by 5
      fadered +=5;
      analogWrite(ledpin[0], fadered);  // lights LED at current brightness level
      delay(250);  // allows time so button won't be detected multiple times
    }

To this:
if(buttonstate == LOW && fadered >255 && button[x] == 2)
    {
      // if button is pressed increase brightness by 5
      fadered +=5;
      analogWrite(ledpin[0], fadered);  // lights LED at current brightness level
      delay(250);  // allows time so button won't be detected multiple times
    }
  
    if(buttonstate == LOW && fadered < 0 && button[x] == 3)
    {
      // if button is pressed decrease brightness by 5
      fadered -=5;
      analogWrite(ledpin[0], fadered);  // lights LED at current brightness level
      delay(250);  // allows time so button won't be detected multiple times
    }

 
As you can see the fadered check value in the if statement changes to 255 on the up and 0 on the down. Not the program flow seems a bit more logical because the up button now needs to increase the fadered value by 5 and the down button decreases it. Also at the start of the code the values that are set for each color need to change. 255 now is full bright on the LED and 0 is off. Which is why i point out in the code that the 255 lvl is off when using a common anode RGB. So when using a common cathode RGB the logic is reversed. 

To connect more RGBs use an LED calc. Treat each color like its a separate LED. You should be able to string several RGBs in parallel. 
Very well done, I like the ribbon cables too, will have to keep an eye out for them.
mpilchfamily (author)  Dain Unicorn2 years ago
Thanks.

I got a bunch of header a couple of years ago and had several IDE cables around. Just last night i made 3 ribbon cable sets about 12 inches long. Each cacble has 6 wires. One end is soldered to a 6 pin header. The other end keeps the wires separate and soldered to there own pins. Just like the one you see in the pictures. So now i have nice ribbon cables to fill almost all the I/O pins on the Arduino. It makes prototyping allot easier and faster.
Excellent, I'll keep an eye out or the header and single pins... I've got a whole drawer of IDE/SCSI/Serial/Parallel cables and runners from ages past just sitting in the 'keep till free electronics tun in day' box.

You sir, have my envy.
mpilchfamily (author)  Dain Unicorn2 years ago
I got my headers form here.

http://www.goldmine-elec-products.com/prodinfo.asp?number=GP6

They have a $10 minimal order but they have all sorts of interesting items to choose from. I also went with an LED and LCD screen from them. 
tboultwood12 years ago
Wow, This is great! I think you should create a remote for your next preoject :D! Or some wireless communication so you could control it from your laptop when it is in the corner of a room? Just suggesting ideas but it does look really neat well done!