2

I am new to electronics. I have a good amount of programming under my belt however.

I want to know if I am multiplexing correctly or not. My intended output is how I want it, but I am not sure if I implemented it how it's supposed to be, i.e. am I potentially damaging my equipment.

I have 6 RGB LEDs hooked up to my arduino, let's called them L1 - L6.

I have each R, G, and B pin on L1 - L3 connected in parallel, and the same for L4 - L6. Then I have ground on L1 and L4 connected in parallel, and the same for L2 to L5, and L3 to L6.

So this gives me 6 pins to supply voltage to, to which I put a 220 ohm resistor in each one. Then it gives me 3 different spots for ground.

My question is about the ground. How should I control the different 'pins' for ground.

This is what I have right now, and it works, but I don't know if this is dangerous to my equipment for some reason.

I have the 3 ground pins connected to the Arduino in 3 different pins, 7, 4, and 2.

In Setup() I configure these 3 pins as outputs, and I later found out in order to keep them all 'off' I need to set them all to high.

So then in order to turn L1 on to red, I need to turn its red pin to high, but turn its ground pin to low, then L1 turns on.

Using this same technique, I am able to get every LED to every desired color. So I mean it works. But why is this? Is this how I should be doing it? I understand LEDs polarity matters, but why would supplying its cathode with voltage make it turn off? That's the part I'm worried about, am I destroying my LEDs by doing this?

Any and all help much appreciated!

Here is how I have it all wired up for clarity.

enter image description here

1

So I mean it works. But why is this?

It works because the LED inside the RGB LED, all three of the LEDs inside have the characteristic of a diode, this means it will allow current flow in one direction, but will stop, or restrict it in the opposite direction. Also are you asking why it works because of your specific wiring?

Is this how I should be doing it?

Yes, how you are doing it is fine. Although I would suggest you use NPN transistors to drive your cathodes of the LEDs.

  • This will at least remove any worry of applying 5v to the cathode.
  • It will also reduce the amount of current your I/O pins have to handle.
  • You should also move the resistors from the cathodes to the anodes as this is more reliable and pretty much the norm.

I understand LEDs polarity matters, but why would supplying its cathode with voltage make it turn off?

This works because of the theory of the p-n junction, (inside construction of a diode), this means that because of the construction of the diode it requires the voltage on the Cathode to be at a lower potential. So that means when you set the output HIGH the 5v on the anode and the 5v on the cathode "stop" current flow because it stops the breakdown within the p-n junction.

That's the part I'm worried about, am I destroying my LEDs by doing this?

No you are not, the LED acts as a diode and when the potentials are the same, current doesn't really flow and thus doesn't do anything to the LED.

1

LEDs are not powered by a particular voltage level, but by the voltage difference between anode and cathode. That's why you need to drive cathode pins (7, 4, and 2) LOW to switch the LEDs ON and HIGH to switch them off. A truth table could help:

╔═══════╦═════════╦══════════════════════════╦═══════════╗
║ anode ║ cathode ║ voltage anode to cathode ║ led state ║
╠═══════╬═════════╬══════════════════════════╬═══════════╣
║ LOW   ║ LOW     ║ 0V                       ║ OFF       ║
╠═══════╬═════════╬══════════════════════════╬═══════════╣
║ LOW   ║ HIGH    ║ - 3.3V                   ║ OFF       ║
╠═══════╬═════════╬══════════════════════════╬═══════════╣
║ HIGH  ║ LOW     ║ + 3.3V                   ║ ON        ║
╠═══════╬═════════╬══════════════════════════╬═══════════╣
║ HIGH  ║ HIGH    ║ 0V                       ║ OFF       ║
╚═══════╩═════════╩══════════════════════════╩═══════════╝

Your schematic looks safe to me, but be aware that if you decide to illuminate L1, L2 and L3 to the same color simultaneously (e.g drive red line HIGH and pins 7, 4, and 2 LOW), your LEDs will not have uniform brightness. Only one of the cathode pins should be LOW at a time, otherwise you will end up in the situation described here.

  • I see what you mean. I'm having trouble trying to figure out PWM now and I don't know how to make L2 @ 255 red while keeping L1 @ 127 red - because they use the same red pin (11). – amallard Apr 20 '16 at 16:39
  • 2
    first drive cathode L2 low, L1 high, and PWM @255. Then drive cathode L1 low, L2 high, and PWM @ 127. repeat about 100 times per second so both LEDs appear lit simultaneously. – Dmitry Grigoryev Apr 20 '16 at 16:46

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.