Controlling an RGB Led With Arduino and Processing





Introduction: Controlling an RGB Led With Arduino and Processing

This instructable (my first no less)  shows how to control an RGB led using processing and arduino.

The key feature being the colour is selected by clicking on an image, the RGB value of the pixel you click on is processed and sent to the audrino which then outputs that same value.

Obviously the match isn't perfect especially at darker colours as I'm yet to see any LED do black very well, but the project should hopefully provide some insight to those of you starting with arduino and other microcontrollers.

Feel free to ask any questions in the comments and I'll answer them as best i can.

Also as i am new to instructable publishing let me know any improvements i could make on this or future instructables.

Video below shows the final result: (if it wont play right click and go to watch in youtube)

Step 1: What You Need

Arduino or similar
1 x RGB led (Dispersed, i used some super fine sand paper as the one i had was water clear)
4 x Connection Wires
1 x Breadboard

3 x Resistors if you plan to leave this on for extended periods.

use this tool to calculate resistors specific to your LED


(This can be done in other software packages but this instructable is to get people started with arduino)

Step 2: Setting Up the Hardware

 Refer to the images below for how the equipment is set up.

Note: My RGB Led is common cathode, if yours is common anode the second pin should be connected to a voltage supply not ground.

Step 3: Software

So whats going on. basically we've set the arduino up to respond to a particular message. this message consists of a header (the letter "C") a dud byte (some strange serial problems caused this to be implemented) and the bytes of data (R G B respectively)

All processing is doing is generating these messages based on a pixel in an image, when we click the mose location is recorded and the message is built and sent to the audrino over a serial connection.

See the attached files for the software for this project, hitting run in processing should bring up a screen like the one below, although it will depend on what image you choose to load.

ColourMap goes in processing

RGB_LED_arduino_code goes in (you guessed it) arduino.

Make sure you load this onto the arduino before you run the processing file or it wont do anything.

if you having trouble check the following:

Is the arduino plugged in
is the arduino power light on
have you wired the led correctly
have you chosen the correct serial port in processing

if your still having trouble post a comment below and I'll do my best to answer it.

Step 4: Enjoy

 Enjoy your new RGB Led. To extend this you could:

-add more leds
-add xBees 
-Add some nice fading effects between colours

the options are limitless.

hopefully this has helped some people to understand arduino and processing a little better.

2 People Made This Project!


  • Epilog Challenge 9

    Epilog Challenge 9
  • Paper Contest 2018

    Paper Contest 2018
  • Science of Cooking

    Science of Cooking

We have a be nice policy.
Please be positive and constructive.




i cant download the files. it comes only FZFOSYCG5FRGO1O.tmp

They are text files. Just change the names.

-descargar imagen completa "FF17LKFG5FRGO1J.MEDIUM.jpg"
-convertir formato a .png y cambiar nombre a "RGBR"
-colocarlo en la carpeta del sketch y run ;)

I'm getting the following NullPointerException error:

"The file "RGBR.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable."

It breaks at 


Anyone had this problem, before? Thank you!

having the same issue, did you ever figure this out?


Also should have mentioned, Mac OSX. Thanks!


I used your code for a project without use of "Processing"

I added an LCD to show the red green and blue value by printing "one[1"...."one[3]

When I send "C" or "CL" followed by values like 255 128 128 (for example), or anything else, everything that shows up are "0" on the screen.

I tried lots of methods : "CLFF00FF", "CFF00FF" or C128255128 etc... without success.

Any idea ?

I uploaded a sketch on autodesk simulator (only the micro arduino is used for now) if you want to have a look :

The code of the main loop :

void loop()
if (Serial.available() > 0) {
// get incoming byte:
inByte =;

if (inByte == 'C') {
int* one;
one = getColour();

//1 2 3 not 0 1 2 due to the dud value

lcd.setCursor(0, 1);
lcd.setCursor(5, 1);
lcd.setCursor(10, 1);




what if we use codeblocks rather than arduino for the arduino program?is the processing code that was used here still works?

hello sir, can you tell me if this item is a common cathode or anode please. thank you !!

Common anode. There's a "+" sign on the third photo on the product page