Circuit with 2 reed switches (proximity sensors) output to single GPIO

outdoorsproximity-sensorreedswitches

I would like to use 2 magnetic proximity sensors (normally open reed switches) to determine the position of a chicken door (vertical sliding door) which in turn controls a motor. If the door comes within reach of the first (lower) switch, the motor should slow down some. When both switches are closed, the motor slows down even more and finally when only the second (upper) switch is closed the motor stops completely.

I would like to use a simple circuit that generates a voltage that can be read with a single GPIO (ADC). I would prefer an output that matches the following truth table:

(S1 = bottom switch, S2 = top switch, x = open circuit)

S1, S2, Output
 x   x  0V 
 1   x  1.6V 
 1   1  3.3V
 x   1  5V

The output does not need to be in that order, but it needs to be distinguishable (at least 1/4V between states).

If at all possible, I would like to use only discrete components.

Best Answer

I think using 2 digital inputs is the way to go, but absent that, you want to build a 2-bit Digital to Analog Converter.

http://tabatha.esg.utulsa.edu/digital/pages/r2r-alt.gif

This pic, from http://tabatha.esg.utulsa.edu/digital/pages/r2r-alt.gif, shows a 3 bit converter. You would simly omit the bottom bit, leaving off the 2K resistor at V1 and the 1K resistor attached to it.

You won't get your table, but you will get unique voltages for each bit. For this 2-bit converter, if your switches provide 5V, one bit will add 2.5V to the output, and the other will add 1.25V. So, none on would be zero volts, if the switch attached to the LSB is on and the other off, you'll have 1.25V, if the switch attached to the MSB is on and the other off, you'll have 2.5V, and if both are on you'll have 3.75V

Your issue with this approach will be implementing it with SPST reed switches. You may need an op amp buffer on each one.