5

I'm an Arduino beginner and I recently bought a cheap starter kit on eBay. One of the lessons in the starter kit is an RGB LED controlled by 3 PWM output pins. However, the arrangement of the connections seems a bit funny to me: Strange LED PWM setup

To my surprise, it worked. I could see the three LEDs inside the plastic change colors. Why does this work? Do the PWM pins accept current whilst low? Is this a common arrangement? See the above link for the code provided in the lesson.

0
6

This is a common arrangement and is known as Common Anode, and the I/O pin is said to be sinking current.

To better understand what is happening here it's best to think of an I/O pin as a two-position switch:

enter image description here

When the I/O pin is HIGH point 1 is connected to point 2. When the I/O pin is LOW point 1 is connected to point 3.

So when HIGH the circuit is Vcc -> D1 -> R1 -> Vcc (or the other way around - I have done it that way because of the polarity of the LED), and no current can flow since it has nowhere that isn't at a lower potential than Vcc to flow to.

But when the I/O pin is LOW the circuit is now Vcc -> D1 -> R1 -> GND and so current can flow through it all to ground. As a result the LED now lights up.

One thing you may have noticed now is that the operation is backwards. Set the IO pin to LOW to turn the LED ON. That has the effect, as well, that PWM duty cycles are reversed. analogWrite(ledPin, 0) will be full brightness and analogWrite(ledPin, 255) will be off.

2

Do the PWM pins accept current whilst low?

The pins sink current when low. And yes, that is commonly done. The pins are not "do nothing" at LOW, and "put 5V there" at HIGH. They are specifically designed to try to source (drive high) current when HIGH and sink (drive low) current when LOW.

To have pins (more or less) do nothing, you have to set them to INPUT mode. Then they try to neither source nor sink.

Caveat: if you enable the internal pull-ups they will try to weakly source current.


Is this a common arrangement?

It is quite common, depending on whether the device you are controlling is active high, or active low.

1

The RGB LED is common anode. This is why it is connected to VCC and the PWM pins pulls down to light resp LED.

A common cathode RGB LED would be connect to GND and the PWM pins would pull up to light

Cheers!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.