0

My scheme is very basic: I use RGB LED with Arduino Uno. 5v is connected to anode, and pins 9-11 are connected to cathodes.

When using following sketch, my LED is producing white colour, which red, green and blue components are on:

int redPin = 9;
int greenPin = 10;
int bluePin = 11;

void setup(){}

void loop(){
  analogWrite(redPin, 0);
  analogWrite(greenPin, 0);
  analogWrite(bluePin, 0);
}

But when I refer to docs for PWM:

A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on)

When I write 0 to all pins, I expect led to be off. What am I missing?

7

With your LEDs connected to +5V (AKA "Common Anode"), the PWM signal is reversed.

  • When the output is "on", the voltage on the pin is 5v.
  • When the output is "off", the voltage on the pin is 0V.

The difference in voltage between +5V and the pin for those two different states is:

  • "On" = 5V - 5V = 0V
  • "Off" = 5V - 0V = 5V

So you can see than when the output is off the LED will on because it causes a difference in voltage from one side of the LED to the other, so current can flow. When the output is on the voltages either side of the LED are the same, so no current will flow.

4

Since you've connected to the cathodes the pins are sinking current. As such the LEDS are active low with 0 being almost fully on and 255 being fully off.

1

Your LEDs are connected to the supply voltage. The output must be low to allow the LED to shine.

Output 0 ==> LED on

1
  • I guess this is very basic, but I don't get why.
    – Mighter
    Nov 30 '14 at 13:56
0

When you set the pin value to 0 you are making that pin act as ground. Since the LED had a single anode that receives 5V. When the difference between the anode and cathode is high (Anode - 5V & Cathode - 0V) the LED turns on. When the difference between the anode and cathode is low (Anode - 5V & Cathode - 5V) the LED is off. The larger the difference between the two the brighter the LED. In your code use analogWrite(redPin, ~0); then everything should work. Change 0 above to whatever value you want, less than 255, and it should work. Also do the same for the green and plus pins too.

1
  • Note that PWM doesn't influence voltage, it just creates pulses. Dec 5 '14 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy