# How can I wire a 9-position switch so that each position turns on one more LED than the one before?

I have a 9-way switch like this guy:

And I'm trying to figure out how I can turn on one LED with position 1, 2 with position 2, all the way up to all 9 in position 9.

Obviously I can repeat all the wiring for the LEDs at each position, but that seems silly.

My idea is that with a layout like below, the switch would represent the circled red line (shown in position 3), which would elongate to the right in each successive position until it connects all the lights. How can I do this?

• What operating voltage does each LED require, how much current does each LED draw, and what is the supply voltage? – Bruce Abbott Apr 23 '19 at 0:52
• Your logic defines OR input logic for each LED but easier tinyurl.com/y38aomlp – Tony Stewart Sunnyskyguy EE75 Apr 23 '19 at 2:09
• @BruceAbbott the idea was to use a 9V battery, but if I have to, I can use a DC power supply that fits a 9V-type switching jack. The LEDs draw about 25-30mA but they do the trick at even half-brightness, so there's some wiggle room there. – Isaac Lubow Apr 23 '19 at 3:26
• With ground above and below, your circuit looks like it's from beyond the grave :) – Dmitry Grigoryev Apr 23 '19 at 13:42
• @DmitryGrigoryev Is that weird? I'm used to seeing guitar pedal schematics where they just stick ground wherever it fits... – Isaac Lubow Apr 23 '19 at 18:07

Here is a low tech solution that requires a lot of parts. Only 4 positions shown, you need 45 diodes for 9 positions.

Sunyskyguy has a clever solution if you have a high voltage available.

• Can you do that with fewer diodes if you bring each one in before (to left of\$ the one above it? – Bob Jacobsen Apr 23 '19 at 3:22
• You can remove the horizontal diodes if a slight change in brightness it tolerable. At a high battery voltage (9V), it probably won't be noticeable. – Mattman944 Apr 23 '19 at 7:35
• Only answer that actually answers the question so far. – abligh Apr 23 '19 at 22:08
• @mattman944 thought you might like to see this solution in action... instagram.com/p/BxaSo5BgA3U – Isaac Lubow May 15 '19 at 2:31
• There's a neat optimization problem here where diodes could be omitted at the expense of some brightness variation. There's an obvious 8 diode solution as well as Mattman's 37 diode solution, but you could then introduce some of the "skipping diodes" to cut down on the variation in the 8 diode solution. – Andrew Macrae May 16 '19 at 22:06

Using a regulated current source to light them, wire the LEDs in series and short out the segment which you want to be dark.

simulate this circuit – Schematic created using CircuitLab

You can possibly use a buck-boost converter to make the 30V if you don't already have a suitable voltage.

Here's a simple way to build one using a LM2596S module:

1. Remove the potentiometer and both large capacitors
2. Connect one of the salvaged capacitors between +in and +out (positive to +in), and fit a 1uF ceramic capacitor where the output capacitor was.
3. Connect a 100 ohm resistor from the -output to the centre potentiometer terminal.

Modified in this way, it will create a negative voltage on the -out terminals and act as a 12.5mA current sink at the centre potentiometer terminal (with source at +out) if power is applied between +in and +out.

simulate this circuit

or a XL6009 buck-boost module can be modified. this time just remove the potentiometer and add a 100 ohm resistor, connec 3-30V to the nirmal input terminals and connect the LED string to the output and resistor.

simulate this circuit

• Or alternatively, connect the switch between the anodes and the current source instead of the ground. That way there will be no power draw when no LEDs are lit, and it will be easier to route if you want the LED bar to grow clockwise/to the right when the switch is turned clockwise. – TooTea Apr 23 '19 at 8:02
• Can I do this with an LM317 like this one mouser.com/ProductDetail/ON-Semiconductor/…? – Isaac Lubow Apr 23 '19 at 19:26
• @IsaacLubow, yes, that is suitable. – Jasen Apr 23 '19 at 22:38
• Can you point me to a schematic where an LM317 turns 9VDC into the constant current needed for this setup? – Isaac Lubow Apr 24 '19 at 17:46
• @IsaacLubow It can't - it can only make the voltage lower. You need at least 20 volts to light up the LEDs, but likely more (so can't even use two 9V batteries in series). Look at the LM2596S option, it works well with 9V input too. – pipe Apr 25 '19 at 11:22

One way to achieve your progressive LED lightup as you turn the rotary switch is to use a current sink on the common of the switch and then wire the LEDs across the selector switch terminals as shown below. The constant current sink shown is a low cost way to get a 20mA sink for the LEDs so that there is no brightness variation as the number of lit LEDs changes. This scheme does require a high enough supply voltage that overcomes the forward voltage drop of the series string of up to nine LEDs.

• Can this be done with 9VDC? I'm not familiar with the LM358 or the transistor in your diagram... any documentation would be appreciated! – Isaac Lubow Apr 23 '19 at 19:31
• @IsaacLobow - No it cannot be done with 9V for nine LEDs. If each LED has a 2V forward voltage drop then nine in a string has a totan – Michael Karas Apr 23 '19 at 20:39
• Drop of 18V. The bottom current sink itself requires a few volts as well. 9V may work for three red LEDs – Michael Karas Apr 23 '19 at 20:42
• Is there a converter module I can get that will turn 9VDC into the constant current I'd need at the voltage I'd need? – Isaac Lubow Apr 24 '19 at 17:49
• A constant current boost or buck supply could be used to keep the circuit operating efficiently regardless of how many LEDs are turned on. – Alex Cannon Apr 25 '19 at 14:31

If you’re not wedded to the specific switch you have, get a “progressive shorting rotary switch” to replace it. That works just like your drawing.

• That solves the much smaller of my two problems, yes - it turns out that powering them is the other hurdle. – Isaac Lubow Apr 25 '19 at 18:08

Oldfart and Mattman944 give very similar answers involving complex diode networks. If brightness variation is acceptable a simple diode ladder is sufficient. Red LED's typically have 2V voltage drop and diodes typically have 0.6V voltage drop, so the combined effect of the diode voltage drops in a ladder is can be significant.

With a 9V battery and the switch in position 9, the current limiting resistor for LED 9 will see 9-2=7V and the current limiting resistor for LED 1 will see 9-2-(0.6*8)=2.2V, which will lead to a more than threefold difference in current through the LEDs if the current limiting resistors are of the same value.

If you insist on equal brightness it would be necessary to include all the diodes recommended by Oldfart and Mattman944, but with only a few extra diodes you can mitigate the variation in brightness to hopefully imperceptible levels. By adding three more diodes at the left as in the drawing above, we ensure that with the switch in position 9, LED 5 sees the same voltage as LED 8. The actual voltages across the current limiting resistors are as below. Note that an additional diode between LED's 5 and 2 (not considered in the table below) would improve the circuit further.

LED  Voltage across current limiting resistor
9             7
8    7-0.6   =6.4
7    7-0.6*2 =5.8
6    7-0.6*3 =5.2
5    7-0.6   =6.4
4    7-0.6*2 =5.8
3    7-0.6*3 =5.2
2    7-0.6*4 =4.6
1    7-0.6*5 =4


Another way of balancing the brightnesses is to install diodes in the lines to some LED's to deliberately increase the voltage drop. In the drawing above an additional diode is inserted into the line from switch contact 1 to LED 1, so that LED 1 sees the same voltage regardless of whether the switch is in position 1 or 2. The current limiting resistor for LED 1 can then be a smaller value than the others in order to balance the brightness of this LED with the others.

These are just ideas - for this type of project the best balance of even brightness versus complexity may be best found by experimentation.

• This is brilliant, thanks! I don't mind a slight variation in brightness between switch positions, and I don't mind running the LEDs at maybe half-power either - they're VERY bright. – Isaac Lubow Apr 24 '19 at 18:02
• @IsaacLubow no problem! A couple more tips: get schottky diodes if you can get them at a reasonable price, they have lower voltage drop. And don't get the smallest diodes you can find. uk.rs-online.com/web/p/rectifier-diodes-schottky-diodes/6527359 is an example. Yes, this is a 1 Amp diode! Note that it has a typical voltage drop a little over 0.3V at 0.1A but about 0.5V at its rated current of 1A. Max voltage drop at 0.1A is 0.55V. Voltage drop for a non schottky diode of the same current rating could be double these values. Always read the datasheet. – Level River St Apr 24 '19 at 19:21
• Why use extra diodes to mitigate the brightness variation? Why not do it in the resistors? – Harper - Reinstate Monica Apr 25 '19 at 18:38
• @Harper The price of a diode is a couple of cents more than a resistor so there would be a very small amount of money to be saved if resistors were used instead. It may be possible to do with resistors, but it would require a detailed balancing calculation over the 9 possible switch positions, plus obtaining resistors of different values, rather than grabbing a bunch of identical resistors that are to hand and about the right value. The time and effort would cost more than the savings in parts on a one off project like this. – Level River St Apr 25 '19 at 19:37
• You can use the same value diodes for everything, if you're not a huge fan of math... – Isaac Lubow Apr 25 '19 at 19:38

You can use a buffer per LED like this.

In this diagram, R1 through R3 are pullup resistors. Closing any of the switches will cause the buffer directly connected to it to go to 0, which turns low all the buffers below it. 4050 has 6 buffers. You will need 2 of them for 9 LEDs.

This solution does only needs a voltage to power the 4050 (3V to 20V for CD4050B). You can chain up as many 4050s as you like.

If you can afford another 0.5V drop you can use a massive array of diodes. Here is an example with three LEDS which requires 6 diodes.
(Sorry for the SW, SW2.., circuit lab does not have a rotatory switch symbol)

simulate this circuit – Schematic created using CircuitLab

It might seem like overkill but it would be fewer parts, and possibly less expensive, than some other solutions to use a micro-controller. Many Ardunio boards have over 9 digital output pins - you could drive one LED with each of nine pins. By having the switch pick different points of a voltage divider and feeding it to one analog pin, you could determine the switch position and light up what ever you have decided should be lit up.

• I was thinking of using a voltage regulator like they explain here - allaboutcircuits.com/technical-articles/… and then wiring the lights in series - seems like a good compromise. – Isaac Lubow Apr 23 '19 at 17:48
• Follow-through: Dump the 9-position switch, and use a rotary encoder instead. – Solomon Slow Apr 23 '19 at 18:42
• The switch is what inspired the project, so, not this time! – Isaac Lubow Apr 23 '19 at 19:23
• or use an LM3918 and a resistor chain on the switch – Jasen Apr 23 '19 at 22:37
• An ATMega to this? And still using the switch? Overkill is a joke. There's simple IC to that. – Diego C Nascimento Apr 24 '19 at 21:46

I wouldn't suggest this unless you're eager to climb the learning curve for FPGAs (including buying a programming pod and dealing with a SMT part with lots of pins), but you could use a Lattice LCMXO2 series with internal flash and oscillator. Circuit would look like this (plus some power supply connections, a programming connector and bypass caps):

simulate this circuit – Schematic created using CircuitLab

The programming software (Lattice Diamond) supports VHDL and Verilog.

If you're feeling lucky you could set the outputs to minimum current drive and omit the resistors.

An alternative approach is to use a LM3914 to drive the LEDs, with an external 10-resistor ladder powered from the reference voltage. Then the rotary switch simply selects a voltage from the ladder which will light the required number of LEDs.

This is just an outline; for example, the topmost resistor of the ladder would be selected to set the step voltages within the tolerance (which in my experience is pretty tight) of the LM3914 comparators.

In addition, the whole thing will run off 3.3V supply

Similar to the micro controller method, another way is to use a OP amp ICs. The positive inputs are all connected together and they connect to a potentiometer that produces varying voltage, instead of a switch. The negative connections connect to a series of resistors to give each one a different Voltage. As the knob is turned, the lights turn on one by one.

This type of circuit is used in power inverters that have those 10 segment LED strips to tell you how many Amps the inverter is putting out. I believe they have all the OP amps in one IC.

I know it's not an exact answer to the question since it doesn't use a switch, but it likely accomplishes what you want.

Edit 2: It's still possible to use a normal switch that connects only one contact at a time. Connect all the negative OP amp inputs to a low Voltage like 1V. Then connect each switch output to each op amp Positive input. Put a large resistor like 100k on the switch input and connect that to the positive power supply. It needs to be a big resistor to not let enough current through to make the LED above turn on noticeably, since the positive inputs will be connected to an LED anode from another OP amp. Now when you turn the switch, one LED will come on at a time. To make all the LEDs next to it come on too, just connect the output of each OP amp to the positive input of the one under it. The forward voltage drop of the LEDs will much too high compared to the 1V reference Voltage to take enough Voltage away from the positive input of the OP amp under it, so the LED won't prevent the OP amp from turning on, but other non LED loads might. This assumes that the OP amps are the current source only type. Current source and sink op Amps can't be used since it will prevent the positive input of the other op amp from going high. Many OP amps are current sink only, so in that case the LEDs would have to be arranged with the cathodes connecting to the OP amp inputs, and the rest of the circuit switched around. Don't forget to use pull up or pull down resistors for the OP amp inputs that are connected to the switch. The same resistor value that was used to connect the switch to the positive Voltage supply should be fine. I hope that's not too confusing.

Edit 3: It looks like someone else posted a similar but simpler solution using buffer ICs instead of OP amps.