# Need circuit for DIP switch to turn on 4 LEDs

I have a project where I want a 4 position rotary dip switch (BCD) type to turn on 4 LEDs. The switch will also be connected to 2 Arduino inputs, so I can tell which of the 4 positions is selected.

Switch Switch Pins

## Position A B

1 0 0 2 1 0 3 0 1 4 1 1

Pretty simply binary stuff. I want to have 4 LEDs connected to the circuit but I only want one LED to be on at a time. For example, LED1 would come on when switch was in position 1 and the other 3 LEDs would be off. I am not using the Arduino to control the LEDs, I don't have enough I/O available. This is probably pretty easy with some logic circuits but I'm not familiar with designing anything like that. I'd appreciate any help.

The switch will also be connected to 2 Arduino inputs

And

4 LEDs connected to the circuit

Are the LEDs to be drive by the switch or the Arduino?

EDIT:
Use a 74HC139 instead of this cct.

Thanks! I can't wait to try out the circuit. The LEDs would be driven by 5v from the Arduino, like you have it in this circuit.

The chip you are after is a (very common) 74HC139. It takes 2 inputs in a binary form and sets one of its outputs low accordingly. Connect each LED between an output and +5V with a suitable resistor each (anode to resistor to 5V, cathode to '139 output), and the switch outputs to th inputs. Connect the /G input to ground, and it should light each LED up for you in sequence.

The LEDs would be driven by 5v from the Arduino

Yes

74HC139 is 2 to 4, I think he wants 4 to 2.

The switch outputs 2 bit binary according to the truth table he posted. Ergo, he wants 2-to-4 , i.e., 74HC139.

I missed that, yes the 139 is they way to go.

I'll check out that chip. The problem with the circuit above is that in position 4 their would be power to switch pins 2 and 3. There is no pin 4 on the dip switch.

ScottG: I'll check out that chip. The problem with the circuit above is that in position 4 their would be power to switch pins 2 and 3. There is no pin 4 on the dip switch.

The circuit above looks like it's for converting a standard 4-position switch into a 2-bit BCD switch - not what you're after.

ScottG: I am not using the Arduino to control the LEDs, I don't have enough I/O available.

Are you sure? Have you used up the 'analog' pins as well?

So 1 LED for each of the 4 positions, is that right?

If so just use a decoder like the 139 or 138, this is a no-brainer, or have I missed something?

Rob

So 1 LED for each of the 4 positions, is that right?

If so just use a decoder like the 139 or 138, this is a no-brainer, or have I missed something?

Rob

It’s a no-brainer if you read the question right in the first place

I just took a look at the 74HC139 (I never used one), it should do exactly what I need. Thanks.

majenko:

Graynomad: So 1 LED for each of the 4 positions, is that right?

If so just use a decoder like the 139 or 138, this is a no-brainer, or have I missed something?

Rob

It's a no-brainer if you read the question right in the first place ;)

2 or 3 more kicks will probably do it :sweat_smile:

@ScottG Do you have a LINK to the switch you are using?

LarryD: @ScottG Do you have a LINK to the switch you are using?

Do you need help with the 138/139 wiring?

LarryD: Do you need help with the 138/139 wiring?

Nope. I looked at the data sheet, it seems pretty straight forward.