Go Down

### Topic: How to read 5 buttons with only 4 I/O lines (Read 3385 times)previous topic - next topic

#### krupski

#15
##### Jun 08, 2014, 04:13 am

Not really.

I have only 4 digital I/O lines left on my Arduino; the others were taken up by other things.  I was wondering if there is a way, using minimal external circuitry, to read 5 buttons with these 4 I/O lines, assuming I have power and ground as well?

Do they have to be read individually (only one button pressed at a time) or can you press combinations of buttons?

One button at a time: Some sort of multiplexing.

eg. There's 15 binary combinations of four bits.

You can therefore have fifteen switches, each switch connects a combination of pins to ground. You read the combination as a binary number.

If you need to read multiple button presses in any combination then you need a shift register. There's no way around it.

You would need diodes to encode the switches to produce binary values.
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

#### dlloyd

#16
##### Jun 08, 2014, 04:20 amLast Edit: Jun 08, 2014, 04:25 am by dlloyd Reason: 1
Quote
Actually, with my design, each switch only needs to be SPST (and the Arduino running code to drive outputs and read inputs (set as INPUT_PULLUP) sequentially to determine which one was pressed.).

Interesting. Could you provide a circuit or brief description of its connections?

EDIT: Previous post came in at about the same time ... you can disregard the above as I now understand you're using diodes.

#### Paul__B

#17
##### Jun 08, 2014, 12:59 pm

Actually, with my design, each switch only needs to be SPST (and the Arduino running code to drive outputs and read inputs (set as INPUT_PULLUP) sequentially to determine which one was pressed.).

Yes, perfectly easy.  Four I/O with six buttons in a net.

(Can't find a diagram for four!)

Drive each of the first three low in turn and read the remaining as inputs.  Six readings the combinations of which can be decoded to indicate each of the six buttons pressed individually, three simultaneous pairs of buttons can be distinguished or other multiple indecipherable combinations detected.

#### fungus

#18
##### Jun 08, 2014, 01:46 pmLast Edit: Jun 08, 2014, 02:43 pm by fungus Reason: 1

You would need diodes to encode the switches to produce binary values.

Oh, yes. Silly me.

Are we only allowed to use wire, nothing more?

Call the pins 1,2,3,4.

Connect 1 to GND via a switch. Read as normal.

Connect 3+4 to 1 with two separate switches. They will only work when 1 is OUTPUT_LOW, not when 1 is INPUT_PULLUP.  (nb. They will ghost if you hold down switch 1)

Connect 3+4 to 2 with two separate switches. They will only work when 2 is OUTPUT_LOW, not when 2 is INPUT_PULLUP.

Total: Five switches

nb. You could add more switches from 2+3+4 to GND, etc., but that's more than you need.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Go Up