3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Controlling an RGB Led with Arduino and Processing

Controlling an RGB Led with Arduino and Processing
«
  • DSC_6858.jpg
  • DSC_6882.jpg
  • DSC_6878.jpg
  • DSC_6881.jpg
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 1What You Need

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)
« Previous StepDownload PDFView All StepsNext Step »
34 comments
Feb 11, 2010. 12:55 PMsmessud says:
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.


Feb 21, 2012. 3:24 PMpcooper2 says:
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.
Feb 10, 2012. 2:12 PMamir_t_h2 says:
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,
Dec 26, 2011. 5:30 AMdundee5 says:
Version without use of Processing (constantly changes color):
https://gist.github.com/1521148
Oct 23, 2011. 9:17 AMsupralova11 says:
Thank you so much :)
Aug 14, 2011. 1:05 PMcmanrique says:
dude im having problem with the color map  ,  please help me with that  and dude this is a n awesome project

Jul 15, 2011. 3:55 AMZedone Two says:
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
Jun 24, 2011. 11:35 AMZdProjects says:
Finally got it to work! My computer says my Arduino is in COM7 but I needed to put in "[3]" for the myPort!.
Jun 7, 2011. 6:56 AM32teeth says:
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.
Apr 28, 2011. 1:24 PMjelmareanvlad says:
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....
Apr 17, 2011. 12:14 AMpdunandf says:
great example thanks - having problems with getting the right colour from processing to arduino but it is a matter of patience, I guess
Nov 14, 2010. 4:39 PMclawlor88 says:
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!
Sep 23, 2010. 9:35 PMscottyb4996 says:
I am confused. How do I get Processing to open up the picture? Basically where do I put the image and the code at?
Sep 12, 2010. 7:56 PMwhiskey_14 says:
this is pretty sweet, thanks for sharing!
Apr 5, 2010. 1:07 AMsapc says:
what do you mean by processing
Aug 21, 2010. 7:27 PMAbrahamFroman says:
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!
Jul 11, 2010. 9:00 AMCCOTTER247 says:
The software wont work!! Help! It downlaids a a .tmp file and processing and arduino doesnt recognize it!
Jul 23, 2010. 6:26 PMArduino Guy says:
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.
Jul 23, 2010. 8:09 PMCCOTTER247 says:
Thank you! I how have it working!!! How do I calibrate the color?
Jul 29, 2010. 3:19 AMArduino Guy says:
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.
Jul 29, 2010. 2:11 PMCCOTTER247 says:
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?
Jul 30, 2010. 7:20 PMArduino Guy says:
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.
Apr 13, 2010. 1:39 PMvIDo says:
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
Apr 5, 2010. 2:45 AMsapc says:
where s the picture file and your code didn't work
Apr 5, 2010. 1:02 AMsapc says:
for the serial part
 myPort = new Serial(this, Serial.list()[0], 9600);
is that your com port
Mar 29, 2010. 5:31 AMtangeeble says:
 Is this tutorial possible with a single anode rbg led?
Mar 2, 2010. 2:50 PMxVirus says:
what kind of a program, that is beside the (arduino). With the big P on it
Feb 17, 2010. 8:43 AMBrunoG says:
(removed by author or community request)

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
7
Followers
1
Author:smitec08
Undergraduate Electrical Engineer and Electronics/Programming enthusiast.