# Wiring for RGB switch?

I am trying to figure out how to wire up a RGB switch, and struggling a little bit…

Here is a picture of my rough wiring diagram:

I am wanting to use RGB led switch, with common anode as shown in the diagram on the proffieboard website.

I am a total newb, and don’t really know which. if any, resistors I need? If I’m using the 6V version of the switch, would I even need add a resistor, or can I rely on the internal one? Or should I go with the model with no built in resistor and just add my own?

Or should I just add the 70 ohm resistor between the anode and the board?

I feel like I am missing something obvious here, so any help would be greatly appreciated!

Any help is appreciated!

I think the part you’re missing is some knowledge, so let me drop some…

LEDs are weird.
A regular light bulb produces less light if you reduce the voltage, down to a point where it doesn’t produce any light at all. Of course, if you give it too much voltage, it burns out.

LEDs do the same of course, but the range of voltages is really narrow. A LED made for 2.1v will produce no light at all at 1.8 volts, and burn out at 2.5 or so. This makes it difficult to control LEDs by altering the voltage.

Luckily, the amount of light produced by a LED is generally proportional to the amount of current going through it, and while the voltage will change very little from “off” to “full on”, the current will change from 0 to 20mA (or whatever the maximum current of the LED is.) Most small LEDs target 20mA, but you would need to read the specifications to know for sure.

Anyways, by adding a resistor to the LED, we get something that behaves more like an old-fashioned lightbulb, and the range of input voltages becomes larger. Let’s see what happens when we add a 70 ohm resistor to a 20mA @ 2.1v LED…

The circuit basically looks like this:

   (+)-----[=====]---->|------(-)
R       D


Every component has to obey ohms law: R * I = V (R = reistance in ohms, I = current in amps, V = voltage)
Voltage adds, so V_{input} = V_{resistor} + V_{diode}
Current flows through the circuit, and since there are no branches in the circuit, I_{diode} = I_{resistor}

However, we don’t actually know the resistance of the diode.
In general though, the volt-to-current slope is so steep, that we can assume that the voltage across the diode is always going to be ~2.1 volts if possible.

That means that the voltage across the resistor is doing to be whatever remains of the input voltage.

So the current going through this circuit is going to be I = \frac{ V_{resistor} }{ R_{resistor} } = \frac{ V_{input} - V_{diode} }{ R_{resistor} } = \frac { V_{input} - 2.1 }{ 70 }
We can make the following table:

V_{input} current
3.0 13mA
3.5 20mA
3.7 23mA
4.0 27mA
4.2 30mA

Since battery voltage will go up to 4.2 volts, we can see that a 70 ohm resistor would not be enough to limit the current to 20mA. To calculate the exact right resistance, we can do:

R_{resistor} = \frac{ V_{resistor}}{ I_{resistor} } = \frac{ V_{input} - V_{diode}}{ I_{diode} } = \frac{4.2 - 2.1}{0.020} = 105 \Omega

Any resistor larger than this will keep the LED safe, but reduce brightness.

Ok, math, great, but how do you apply this in practice?

Well, the first thing to do is to try to find the specifications of the diodes inside the AV switch. If you can find out what the recommended voltage and current is, then you can use the math above to figure out what resistors to use. If you can’t find that information, then you have to guess or measure these values, which is a whole other explanation, so I’m going to leave that out for now.

The good news here is that you can bypass all of these issues by using a resistor that is “big enough”. It might reduce the brightness a bit, but it would work. I bet this is exactly what would happen if you used the 6V version.

In general, the LED voltage depends on the make and chemestry of the LED, but in practice, red LEDs usually have voltages around 2.1, green have voltages around 3.0 and blue have voltages around 3.1.

This leads us to the whole “one resistor for multiple LED” idea… It’s not a good idea, because if you try to make a purple color by turning on red and blue at the same time, then the red led will reduce the voltage across the leds to 2.1 volts. At that voltage the blue led will simply shut off, so you end up with red instead of purple. In theory, it’s possible to program the board to only turn on one LED at a time and produce the purple color by quickly alternate between blue and red, but there is no support for that in ProffieOS today. (In fact, ProffieOS tries very hard to turn on all LEDs at the same time in case the output pads are joined together.)

tl;dr;

Either use the 6v switch, or use one resistor per LED, do not try to use a single resistor.
If you don’t know what resistors to use, 120 ohms for red, and 70 for blue and green might be a reasonable-but-safe guess. (Assuming the LEDs in the switch can handle 20mA…)

2 Likes

Thank you so much for the in depth reply! I think I’m just gonna go with the 6v switch to simplify things.

Thanks again for your explanation, it really cleared things up! 