Electronic – reading the position of a switch using a microcontroller

switches

I would like to use a micro controller to read the position of a switch.

The example and image below is for illustration purposes only.

For example if a switch is at Position A, a 5V signal might feed DIGITAL INPUT 1. Similarly if the switch is at Position B, a 5V signal might feed DIGITAL INPUT 2. To make the signals useful, they would be on exclusivity to the other.

i.e.

Position A   Position B   |   DIGITAL 1      DIGITAL 2
--------------------------|----------------------------
    ON          OFF       |     HIGH          LOW
                          |
    OFF         ON        |     LOW           HIGH

The circuit is powered by the micro controller's 5V supply, and shares a common ground with the micro controller.

Thank you.

EDIT: changed R1 (1 kOhm) to a DC motor, to better represent the actual circuit.

Also, the input voltage has an error or +-0.5V. The resistors have a 5% error tolerance.

enter image description here
https://www.circuitlab.com/circuit/wec9n2/switch-sensing/

Best Answer

While I was drawing the schematic with a DPDT switch, Pete had beat me to the answer.

enter image description here