Some notes on your RGB LEDs

So we didn’t get the chance to do color mixing with the LEDs, but I hope you all try it out. Here’s some notes on them….

The LEDs you have in the ARDX kits are common anode, that means that one leg goes to power, and the others connect to your Arduino through a resistor (a small one, like the 560 ohm ones in your kits). A simple circuit without any sensors may look like this :


(my illustration above may not have the proper wiring for the LED, I was doing it  on a plane without a datasheet, check the documentation in your kit to verify the wiring.)

To make the elements in the LED glow, you need to create a voltage difference across the anode (connected to power) and the pins connected to the Arduino. When you create this difference, current will flow from power through the LED’s elements, turning it on.

So, in order to PWM the LED’s pins, you wouldn’t do analogWrite(greenPin, 255) to turn it to full brightness. That would put 5V on the Arduino’s output, and there would be no voltage difference. Instead, you would reverse the numbers so that 0 = 5V and 255 = 0V. Here’s some code that should fade the LED through various colors using the above circuit

This simply adds or subtracts a number from the analogWrite() value to each pin. If I did this correctly, you should see the colors in the LED slowly change over time. Groovy, man.

If you wanted to add interaction to this, like, say a potentiometer to each color for accurate mixing, wire up three sensors to A0, A1, & A2. Each of these will control a different color element in the LED. Illustration and code are below.


Happy blinking!

Comments are closed.