Using SPST switch as digital input?

Yes it would work as you described. That is called a pull-down resistor because it assures that when the contact is open the digital input is at the logic state 0 (low). Usually you can use a 10 KΩ resistor for this purpose.


The most conventional solution would be to connect one side of the switch to ground. Connect the other to the digital input, and also to a resistor between 1 and 10 K ohms going to the positive supply.

Going the other way, with a pull down resistor as Bruno describes, is possible but less preferred. Many inputs already have a degree of implicit pull-up and will read a '1' if unconnected, though not quite reliably. But if your switch is already connected to the positive rail, then a pull down is an okay solution, though many prefer to use a small resistor when connecting logic inputs to the positive rail.

Many microcontrollers also have internal pullup and/or pull down resistors on GPIO pins which can be enabled by writing to a configuration register. If you are driving an input of such a microcontroller you might not need an external pull up/down resistor at all, though not every microcontroller features these.


That will work, and will give you positive logic: a high level (logic "1") when the switch is closed.

But like Chris says the inverted thing is more common: switch connected to ground, and a pull-up (instead of pull-down) resistor to the power supply. Your logic will be inverted: a logic "1" will correspond with an open switch.

A good reason for the pull-up version is that most microcontrollers have them integrated, and you can enable/disable them depending on your needs. Some microcontrollers also have configurable pull-downs, but these are less common.

If you want an external pull-up 10 kΩ may be a good value. A microcontroller's input can have a leakage current of up to 1 µA, and then 10 kΩ will drop a negligible 10 mV. Lower values are certainly possible, but keep in mind that they will have a larger current to ground when the switch is closed. A 1 kΩ resistor will draw 5 mA at 5 V supply, which is a waste of power really. For the 10 kΩ that's only 500 µA. For very low-power applications you may increase the value to 100 kΩ, but remember the leakage current; 1 µA will give a 100 mV drop!