Multiple spst switch sensing

I'm building a 'busy box' for a toddler that will have several SPST switches on it. What I would like to do is wire those switches such that:

  1. I only use 1 pin on the Arduino, and
  2. The Arduino will recognise when any switch has been thrown, whether on-to-off or off-to-on, and irrespective of the status of the other switches.

The idea is that toggling any switch will trigger an activity such as lights flashing, music playing, etc.

I'm not sure if it's even possible, but there are a lot more creative minds out there than mine and so I thought I'd toss this out there.


Why ?

How many switches ?

What other things are connected to the Arduino ?

I'll probably have 6 or 7 different switches, and don't want to tie up that many pins if I don't have to. I'm planning on having a microSD reader attached, various LEDs, and perhaps other things as well. This is still in the brainstorming stage so everything's on the table so to speak.

Are they SPST? Or are they actually SPDT? How many terminals does each switch have? If they are SPDT, you can build an R/2R resistor ladder and feed that to an analog input.

For sounds effects/noises? I would recommend a dfplayer mini rather than an SD card reader. Easier to use, similar size, built-in amplifier, much better quality output.

SPST - typical light switches, toggle switches, etc. But, yes, the resistor ladder would work with spdt switches.

Will look into the dfplayer mini. Thanks.

I gets a bit complicated to sense multiple switches on or off with the analog approach.

If you want to minimize the number of pins used by the switches and LEDs you could use I2C expanders like the MCP23008 (8 GPIO) or MCP23017 16 GPIO). They have 8 or 16 GPIO pins that can be configured, independently, as input or output. There are internal pullups available on every pin and pin change interrupt on each pin.

Don't need SPDT. SPST will work just fine with resistors in binary scale.

Paul_B, how would that work? Thanks.

Good suggestion. Thanks.

Each switch connects a given (different) resistor to ground from the analog input. You have a pull-up resistor to Vcc whose value is toward the middle of the binary sequence of resistor values (110, 220, 470, 1k, 2k2, 4k7, 10k), so say 1k.

If you want to save current, you connect the pull-up to a control pin instead of Vcc and only pull it up when you want to read the switches.

This should work with up to seven switches allowing you to actually figure out which switches are operated at any given time, though you may need to adjust the resistor values.

No need to delete, just modify! :grin:

Thanks for that. I'll set up a test scenario to help get my head around the concept, but, if, say, every switch was "on" (i.e. closed), and I read the analog input, wouldn't it just read the lowest resistance figure, as if the only closed switch was the first one? In other words, would this only work if lower resistance switches had been turned off? (Sorry for all the questions; I'm still learning.)

No, every combination of the switch settings would give a different resistance, because the resistor values would combine, either in series or parallel (not sure which @Paul_B is suggesting).

Hi, @Dblackb99
This link might help with your query.

Tom... :grinning: :+1: :coffee: :australia:

If you read my description you will see it suggests each of the (series) resistor/ switch pairs is in parallel with the others, all between the analog input and ground,

Of course you can alternately put all the resistors in series, and have each switch bridge one of them (except the pull-up).

Thanks everyone for your input. I learn something new every day I'm on this forum!