Go Down

Topic: multiple switches -analog pin (Read 147 times) previous topic - next topic

steliosp

Hi
I want to connect a number of switches on an analogue pin.

So far i've seen two solutions that both work ok. One with a voltage divider and one that does not require a connection to the 5V rail.


Since they both work, is there any reason in particular i should choose one over the other? (Accuracy - Reliability in the long run etc.)





Wawa

Second diagram is less dependent on bad contact resistance of the switches, so might be better long term.

First diagram won't work without pull up.
That could be done in code, but then you need to calibrate because of the unknown resistance of the internal pull up.
Leo..

Grumpy_Mike

Quote
Since they both work,
No the top one as drawn will not work. Unless you enable the internal pull up resistor on the analogue input pin. And the problem with that is it is not very well defined.

The bottom one is poor as well as the R8 pull down resistor is way too high.

There are much better ways of making this circuit, you should not connect the analogue input to the switches. You should connect it to the resistor chain and have the switches short out resistors in that chain. Your problem then is when more that one switch is pressed you can not see which ones are being pressed.

Paul__B

Clever though it be, my experience of a number and variety of faulty devices such as video monitors and MP3 players is that this clever trick to minimise connecting wires and control pins on ICs is a singularly common mode of failure where contamination of the lubricant in the "tactile" switches or degradation of the IC itself - perhaps related to static damage - causes ciphers where spurious responses occur.

steliosp

Thanks for your time and input!
Yes the diagrams work with their respective code of course (Pullup - calibration etc.)
I have a four-way joystick switch, so it wont be possible for two of them to be closed simultaneously.  Hence the simple  approach using just a pin.

There are much better ways of making this circuit, you should not connect the analogue input to the switches. You should connect it to the resistor chain and have the switches short out resistors in that chain. Your problem then is when more that one switch is pressed you can not see which ones are being pressed.
Does that mean i have to flip around ground and analogue pin in the first diagram?

Grumpy_Mike

Quote
Does that mean i have to flip around ground and analogue pin in the first diagram?
See his page https://tronixstuff.com/2012/02/29/tutorial-analog-input-for-multiple-buttons-part-two/

Go Up