Go Down

Topic: Multiple Buttons to digital pins. Possible to simplify my circuitry? (Read 4030 times) previous topic - next topic

GregFinger

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.


TonyWilk

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

  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

GregFinger

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?

Grumpy_Mike

Quote
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.

Quote
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.

GregFinger

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.

Quote
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

Mikeb1970

Quote
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

Grumpy_Mike

Quote
I do think that it is possible to just use one resistor
OK then post a schematic and then we will see.

dougp

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?  


You can do that but you'll not be able to sense which switch is on, only that some switch is on.
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

MarkT

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...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Wawa

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.

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..

Mikeb1970

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

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..

dougp

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.
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

ChrisTenone

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.)
What, I need to say something else too?

Dan_ce

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...

Go Up