29
\$\begingroup\$

I have a 9-way switch like this guy:

9-way

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?

schematic

\$\endgroup\$
8
  • 4
    \$\begingroup\$ What operating voltage does each LED require, how much current does each LED draw, and what is the supply voltage? \$\endgroup\$ Commented Apr 23, 2019 at 0:52
  • \$\begingroup\$ Your logic defines OR input logic for each LED but easier tinyurl.com/y38aomlp \$\endgroup\$
    – D.A.S.
    Commented Apr 23, 2019 at 2:09
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Apr 23, 2019 at 3:26
  • 2
    \$\begingroup\$ With ground above and below, your circuit looks like it's from beyond the grave :) \$\endgroup\$ Commented Apr 23, 2019 at 13:42
  • \$\begingroup\$ @DmitryGrigoryev Is that weird? I'm used to seeing guitar pedal schematics where they just stick ground wherever it fits... \$\endgroup\$ Commented Apr 23, 2019 at 18:07

13 Answers 13

11
\$\begingroup\$

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.

enter image description here

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Can you do that with fewer diodes if you bring each one in before (to left of$ the one above it? \$\endgroup\$ Commented Apr 23, 2019 at 3:22
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Mattman944
    Commented Apr 23, 2019 at 7:35
  • \$\begingroup\$ Only answer that actually answers the question so far. \$\endgroup\$
    – abligh
    Commented Apr 23, 2019 at 22:08
  • 4
    \$\begingroup\$ @mattman944 thought you might like to see this solution in action... instagram.com/p/BxaSo5BgA3U \$\endgroup\$ Commented May 15, 2019 at 2:31
  • \$\begingroup\$ 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. \$\endgroup\$ Commented May 16, 2019 at 22:06
68
\$\begingroup\$

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

schematic

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.

schematic

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.

schematic

simulate this circuit

\$\endgroup\$
6
  • 7
    \$\begingroup\$ 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. \$\endgroup\$
    – TooTea
    Commented Apr 23, 2019 at 8:02
  • \$\begingroup\$ Can I do this with an LM317 like this one mouser.com/ProductDetail/ON-Semiconductor/…? \$\endgroup\$ Commented Apr 23, 2019 at 19:26
  • 1
    \$\begingroup\$ @IsaacLubow, yes, that is suitable. \$\endgroup\$ Commented Apr 23, 2019 at 22:38
  • \$\begingroup\$ Can you point me to a schematic where an LM317 turns 9VDC into the constant current needed for this setup? \$\endgroup\$ Commented Apr 24, 2019 at 17:46
  • \$\begingroup\$ @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. \$\endgroup\$
    – pipe
    Commented Apr 25, 2019 at 11:22
18
\$\begingroup\$

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.

enter image description here

\$\endgroup\$
7
  • \$\begingroup\$ Can this be done with 9VDC? I'm not familiar with the LM358 or the transistor in your diagram... any documentation would be appreciated! \$\endgroup\$ Commented Apr 23, 2019 at 19:31
  • 1
    \$\begingroup\$ @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 \$\endgroup\$ Commented Apr 23, 2019 at 20:39
  • \$\begingroup\$ Drop of 18V. The bottom current sink itself requires a few volts as well. 9V may work for three red LEDs \$\endgroup\$ Commented Apr 23, 2019 at 20:42
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Apr 24, 2019 at 17:49
  • 1
    \$\begingroup\$ A constant current boost or buck supply could be used to keep the circuit operating efficiently regardless of how many LEDs are turned on. \$\endgroup\$ Commented Apr 25, 2019 at 14:31
16
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ That solves the much smaller of my two problems, yes - it turns out that powering them is the other hurdle. \$\endgroup\$ Commented Apr 25, 2019 at 18:08
15
\$\begingroup\$

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. enter image description here

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.

\$\endgroup\$
5
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Apr 24, 2019 at 18:02
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Commented Apr 24, 2019 at 19:21
  • 1
    \$\begingroup\$ Why use extra diodes to mitigate the brightness variation? Why not do it in the resistors? \$\endgroup\$ Commented Apr 25, 2019 at 18:38
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Apr 25, 2019 at 19:37
  • 1
    \$\begingroup\$ You can use the same value diodes for everything, if you're not a huge fan of math... \$\endgroup\$ Commented Apr 25, 2019 at 19:38
5
\$\begingroup\$

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.

\$\endgroup\$
7
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Apr 23, 2019 at 17:48
  • 1
    \$\begingroup\$ Follow-through: Dump the 9-position switch, and use a rotary encoder instead. \$\endgroup\$ Commented Apr 23, 2019 at 18:42
  • 1
    \$\begingroup\$ The switch is what inspired the project, so, not this time! \$\endgroup\$ Commented Apr 23, 2019 at 19:23
  • \$\begingroup\$ or use an LM3918 and a resistor chain on the switch \$\endgroup\$ Commented Apr 23, 2019 at 22:37
  • \$\begingroup\$ An ATMega to this? And still using the switch? Overkill is a joke. There's simple IC to that. \$\endgroup\$ Commented Apr 24, 2019 at 21:46
5
\$\begingroup\$

You can use a buffer per LED like this.

diagram

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.

\$\endgroup\$
4
\$\begingroup\$

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)

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
2
\$\begingroup\$

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):

schematic

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.

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Here's another take on the diode ladder approach, but this time there are diodes on both sides of the ladder so the current through each rung passes through the same total number of diodes whocuh should equalise the brightness. fairly well.

The resistors at the top are there so can to equalise the brightness of short bars and long bars

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
1
\$\begingroup\$

The circuit below does it, requiring two transistors and two resistors per LED.

D90-D92 are optional for brightness equalization in the first and last LED in the chain. They can be replaced by wire jumpers.

Four LEDs are shown, but the chain can be extended without limitation.

Q10, Q20, ... are common-emitter switches that turn the LEDs ON/OFF. Q11, Q21, ... are common-base switches that turn on the following stage when they detect LED current. When any individual switch is closed, its respective stage, and all the stages following it (to the right) turn off. This presents the singular switch position in a bargraph-like fashion.

Q10,Q20, ... collectors can be interfaced to any ground-referenced CMOS logic input through a series current-limiting resistor, for optional switch position monitoring with a microcontroller, etc.

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$

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