Multiple Buttons to digital pins. Possible to simplify my circuitry?

Hello. I'm using an NodeMCU ESP8266, and have 6 buttons attached to six digital pins. They all have 5V connected to one prong on the button directly. The other prong connects to a parallel circuit, where it goes to a digital pin, or across a 10k resistor to GND.

Is there anyway to tighten this up? I'm trying to make it as small as possible. My only idea would be to connect all the buttons to a single higher-ohm resistor and connect that resistor to ground, but i'm not quite clear on the electrical implications of doing that.

I know you can hook all the buttons up to a single analog input pin with a voltage/resistor ladder, but the math involved trying to figure out the combinations of button presses and what the analog input pin will be read as, makes me prefer the multiple digital pin method where i can just flip it LO/HI.

You could connect all your buttons to GND (instead of +5v) at one side, remove all the resistors and set the inputs as:

  pinMode( pin, INPUT_PULLUP );

which just saves you the resistors.

With this number of buttons, any other method will end up with extra components.

If you want to reduce the number of pins you are using... that's a different question.

Yours,
TonyWilk

I think i might've tried doing this earlier, but got a burning smell when i connected it all, so i didn't pursue it. I'll try it again.

Is it possible to just use a single resistor between all the buttons and GND, or should each one get it's own resistor?

I think i might've tried doing this earlier, but got a burning smell when i connected it all, so i didn't pursue it.

Then you did not do it correctly, that way is the correct way to do it.

Is it possible to just use a single resistor between all the buttons and GND,

No because then all the inputs are shorted out and when one button is pressed then all the inputs signal a press.

Grumpy_Mike:
Then you did not do it correctly, that way is the correct way to do it.

Ya, I think i'm slowly coming to realize what is meant. Just use the button to connect between the pin and GND (eliminate any connection to 5V/3.3V) and make sure the pin is set as Pullup. When i tried it before, I had the 5V connected in there, hence the burning smell.

No because then all the inputs are shorted out and when one button is pressed then all the inputs signal a press.

Right, i understand what you're saying, but trying to visualize the flow of electricity, i can't picture it. But it doesn't matter since my current wiring is completely wrong anyways

Is it possible to just use a single resistor between all the buttons and GND,
No because then all the inputs are shorted out and when one button is pressed then all the inputs signal a press.

@GrumpyMike
Without trying to start an argument here, I do think that it is possible to just use one resistor, but that would mean you would require 6 diodes, or am I mistaking here?

With regards,

Mike

I do think that it is possible to just use one resistor

OK then post a schematic and then we will see.

Mikeb1970:
Without trying to start an argument here, I do think that it is possible to just use one resistor, but that would mean you would require 6 diodes, or am I mistaking here?

Since I was about to post this anyway:

Like this?
multiple switches.PNG

You can do that but you'll not be able to sense which switch is on, only that some switch is on.

multiple switches.PNG

It might work very poorly, you've neglected the diodes' leakage current when reversed biased, the
pins would still drain to ground that way (perhaps quite slowly). Note that diode leakage current goes up
markedly with temperature, so it might only work on cold days!

And resistors are cheaper than diodes anyway, and built-in pull-up resistors are free with the chip...

1 Like

GregFinger:
Is it possible to just use a single resistor between all the buttons and GND, or should each one get it's own resistor?

Post#1. No resistors.

GregFinger:
Just use the button to connect between the pin and GND ... and make sure the pin is set as Pullup.

Post#1 again. .....INPUT_PULLUP); // enable the internal resistors (inside the micro)
Leo..

Am I missing something here? (I started very heavy painmedication few days ago, and my mind doesn't work optimally) but if you would connect the blue arrow to a digital pin, and press the switch above it, then the arduino could perfectly tell what switch was pressed, right? The +5v can't reach the other I/O pins because of the diodes. Please, if I'm wrong, then let me know.

Mike

Seems the letters "D" are connected to three digital pins.
That would work, ...if the pins have internal pull up.
In which case none of the parts are needed (except for the switches).
Leo..

Wawa:
Seems the letters "D" are connected to three digital pins.
That would work, ...if the pins have internal pull up.
In which case none of the parts are needed (except for the switches).
Leo..

No. The little dots are just artifacts of the Express schematic drawing software. I did a snip right off the raw drawing - hence the grid markers. The 'D' only signifies a diode. The signal would be taken off the bottom of the resistor. I was attempting to put in an image what was being described in text.

This all assumes the topic is the drawing I posted.

Y'all are making this really complicated. Just hook up your switches like this:

Then use PULLUP in the software. digitalRead() will return LOW when the switch is closed, HIGH otherwise.

(As stated in the very first reply.)

Sorry to revive this thread, but it seemed a better idea than creating a new one.

I'm a bit laden with wires at the moment. I'm trying to read from 10 switches and at the moment I'm using external pull up resistors because I had a problem with fluorescent lights starting up and shutting off in my building inadvertently causing the arduino to think the switches had switched state when they hadn't.

Either the zener diode between ground and VIN, or the smoothing capacitor (same) or the external resistors (I've gone for belt and braces) seems to have stopped that.

Do none of you guys ever have problems with JUST using the internal pull up resistors - even when you have a longish cable? Mine will be about 60-80cm between buttons and arduino...

Dan_ce:
I'm trying to read from 10 switches and at the moment I'm using external pull up resistors because I had a problem with fluorescent lights starting up and shutting off in my building inadvertently causing the arduino to think the switches had switched state when they hadn't.

So what duration have you been using in the debounce code? (And did you use the proper code?)

If I have to use longer wires, then I always use twisted and/or shielded cable.
Good quality solid Cat-5/6 is a good source for twisted pairs.
Never had problems that way, even with only internal pull up.
If you do have problems, add a 100n ceramic cap from pin to ground, close to the Arduino.
If speed is important, lower the internal pull up resistance with an external pull up resistor.
Leo..