Instructables

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)
 
Remove these adsRemove these ads by Signing Up

Step 1: What You Need

Hardware:
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 led.linear1.org/led.wiz

Software:
Arduino
Processing

(This can be done in other software packages but this instructable is to get people started with arduino)
theorio9 months ago
Can I use a Bluetooth Arduino with this? (I'm new to this)
Raphango theorio6 months ago
Sure... =)
Just have to add some changes to the code (kind more complez) but yes, its possible!
Raphango6 months ago
Great ible! Got myself one fully running!
Congratulations!

P.S.: SInce you are using pins 9~11 as PWM (Analog Out), you don't have to declare "pinMode(redPin, OUTPUT);" understand? It's not necessary. Gotta save you a couple KBs... ;D
bodet3281 year ago
I know I'm really late to this, but why is the red part of the colour map blocked off?
jpindi1 year ago
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 

image(img,0,0);

Anyone had this problem, before? Thank you!
jpindi jpindi1 year ago
Also should have mentioned, Mac OSX. Thanks!
smessud4 years ago
A useful ible, but I'm worried that you don't use any resistor.

If you apply the maximum power to the LEDs, with 5V output, I'm afraid they won't live long.

You'll have to determine the proper resistor for each colour, as each LED type has it's own workiing voltage.


LEDs work on current, not voltage. Each type of LED has a forward current "knee" that corresponds to a narrow range of forward voltages. The supply voltage needs to be higher than the knee voltage, but once the knee voltage is exceeded, the forward current rises extremely rapidly in the absence of a current limiting resistor.

Running an LED without a current limiting resistor only works if the die has a built-in constant current source. Some blinking LEDs are built that way, although the three-color LED apparently is not.
smitec08 (author)  smessud4 years ago
 yes this is true. personally mine is one for about a minuet at a time so its pretty safe. i'll add the resistor values now, thanks for reading.
amir_t_h22 years ago
I have problem to run the file. I appreciate if anyone help me to resolve the problem. when i run the first code which map the picture, the error " import does not name a type" appear. it is my first experience with Arduino. I believe something wrong with my library. how can i resolve this problem.
Thank you,
dundee52 years ago
Version without use of Processing (constantly changes color):
https://gist.github.com/1521148
supralova112 years ago
Thank you so much :)
cmanrique2 years ago
dude im having problem with the color map  ,  please help me with that  and dude this is a n awesome project

Zedone Two2 years ago
Could you do an instructable with both an xBee and RGB LEDs? I'm interested to see it work, especially controlling the LEDs separately and wirelessly at the same time :D
ZdProjects2 years ago
Finally got it to work! My computer says my Arduino is in COM7 but I needed to put in "[3]" for the myPort!.
32teeth2 years ago
works well if you change your serial ports
arduino's serial port will be whatever your COM port for uploading the file will be
on processings side the index will changed based on your OS and how many things you have plugged in

on OSX you will get many com ports (usually between 5 and 8 depending on whats plugged in) look for the first one that has TTY in it's property

on PC they will show up as COM1, COM4...

good starting project on communications between software and hardware.
it doesnt work.....I cant find the image for processing and I keep getting a "Null pointer exception" what is that ? I think your code is bad or something...please respond....
pdunandf3 years ago
great example thanks - having problems with getting the right colour from processing to arduino but it is a matter of patience, I guess
clawlor883 years ago
I've had no problem with calibrating or uploading the image. However, i'm getting this error when I try to run the file:

"error: 'import' does not name a type In function 'void setup()':
In function 'void draw()':
In function 'void mousePressed()':"

Anyone know this means? Thanks for any help!
scottyb49963 years ago
I am confused. How do I get Processing to open up the picture? Basically where do I put the image and the code at?
whiskey_143 years ago
this is pretty sweet, thanks for sharing!
PoisonMondo4 years ago
what do you mean by processing
Processing is a multi-platform programming IDE based on Java. It's at processing.org. It's pretty simple to learn and has great support via their forums and the web in general. Terrible name though since it's such a generic word!
CCOTTER2473 years ago
The software wont work!! Help! It downlaids a a .tmp file and processing and arduino doesnt recognize it!
left click the file and press rename, then select tmp and enter pde when the open menu asks " if the file extension is modified the file might become unusable..," press yes. do this with both files and i am pretty shure the one ending in 2K is arduino c code, the other is for prossessing.
Thank you! I how have it working!!! How do I calibrate the color?
You need to make a another background file and import it into processing, or if your asking to change the LED's colour, just run the program and click on the colour you want to change the led into.
I apologize for not being very clear on my last question! I was curious about calibrating the color of the led. When I click a color on the screen it changes the led to a different color than I clicked on. Any suggestions?
try turning on any single colour(red, green, or blue), then disconect all and put each pin of led into the arduino pins, once you get a matching colour leave it connected, do the same procedure for the next colour.
smitec08 (author)  CCOTTER2473 years ago
check the pure RGB values (red blue green) if they seem correct then you know the pins are correct. if they seem a bit off check if you have a common anode of cathode LED. that will change the code if its common anode attach the common anode to VCC and wherever there is an analog out replace its value with 255- that value eg analogOut(X) to analogOut(255-X) if that still doesnt fix it check you resistor values with an online calc to ensure they're in the right range as it may be letting to much power through to the LEDs. Hope that helps. Smitec :D
vIDo4 years ago
first I wanted to thank you a lot for the tutorial.. it was a lot of help..

second I played a little with your code and the code found here to add some twitter to the mix.. now I can use twitter to change the color of my lamp!

just tweet: @colormelamp <color of you choice>
supported colors: red, green, blue, cyan, yellow, magenta & white.
(actually it doesn't matter what's in the message as long as it contains "@colormelamp" and a color)

my code is pretty cruel but it works. the code on the arduino is the same, you'll just have to set the usb port.. the rest should work.. if your gonna try it you could use the same twitter account I used that way our lamps would have the same color!

processing code here
(you can leave the password and username as they are, there not needed)

tell me what you think!

ps. this was my first Processing and third Arduino project so sorry if it doesn't make sense.. :P
PoisonMondo4 years ago
where s the picture file and your code didn't work
smitec08 (author)  PoisonMondo4 years ago
 myPort is the first com port the one the arduino is attached to yours may not be the same.

go to processing.org it is a program named processing

place the image in a folder named 'data' in the same directory as your processing file.
PoisonMondo4 years ago
for the serial part
 myPort = new Serial(this, Serial.list()[0], 9600);
is that your com port
tangeeble4 years ago
 Is this tutorial possible with a single anode rbg led?
smitec08 (author)  tangeeble4 years ago
yes but:
   -anode should be connected to a voltage supply not ground
   -and, your analog outs in the arduino code should be 255-(what they are now)
xVirus4 years ago
what kind of a program, that is beside the (arduino). With the big P on it
smitec08 (author)  xVirus4 years ago
Processing avaliable from processing.org

thanks for reading
BrunoG4 years ago
(removed by author or community request)
smitec08 (author)  BrunoG4 years ago
add a folder named 'data' to the same directory as your processing file, put the colour map image inside, this should fix the problem.

thanks for reading
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!