Electronic – arduino – Are the resistance values (R1 and R2) in this circuit reasonable

analogarduinocurrentsensor

This simplified circuit is intended to sense two limit switches (which can never be closed simultaneously– at least in theory). The voltmeter shown is a place-holder for a connection to an analog input pin of an Arduino. When both switches are open as shown in the diagram, the pin should sense 3V31. Closing SW1 gives 5V and closing SW2 gives 0V.

This works great in simulation, but I am wondering about the total current as shown by the GND probe… My vague newby intuition tells me that there must be some minimum amount of current in order to be sensed by the A/D converter in the Arduino, but I haven't been able to find (or recognize) a spec for this minimum anywhere. (In contrast, the specs for the maximum current that a pin can sink are widely discussed.)

enter image description here

Best Answer

I may be way off base, but I believe this is a case where you don't want to over-think the problem, KISS.

When SW2 is closed the input pin is tied to ground and you should read 0. This is just like the case where an unused pin is grounded rather than left floating.

When SW1 is closed the input is tied to 5V (either Vcc or Aref), and you should read the max value (that is all the binary bits will be 1)

For both of the above cases, you could remove the resistors from the above circuit as they have no affect on the level of the input pin (that is one or the other of the switches is closed).

The only remaining case to consider is when both switches are open. If you did not have any resistors then the input pin would be floating. When the input to the ADC is left floating one would expect to read out semi-random values from the port, certainly not an unchanging value of 0 or MAX (all bits on). While I don't recommend omitting the resistors, you should be able to make this work without them.

While not explicitly part of your question, the more interesting case is if you wanted to detect one of several switches being closed with a single analog input pin. For a reasonable number of pins, say 10, this can easily be done with a resistor ladder ( http://en.wikipedia.org/wiki/Resistor_ladder ). You can also Google R2-R ladder.

For a walk-through of how this is implemented see: http://embedded-lab.com/blog/?p=4040

As an aside, if you only wanted to sense a single switch closure one would most likely use a digital I/O pin rather than an analog one, if available. The most common reason for using an analog rather than a digital pin for detecting switch closures is when the number of digital pins available is less than the number of switches.