Wiring Switches Etc.
Wiring a switch or other sensor with a voltage divider
When using a switch or other unpowered two wire sensor (e.g. many pressure sensors), most microcontrollers require the use of a PULL-UP RESISTOR. This is used to create a voltage divider network, which in basic terms is a three wire hookup consisting of:
- ground
- power
- signal
The pull-up resistor is used with sensors that only have two outputs, including switches, bend sensors, and pressure sensors. The value of the resistor depends on the kind of sensor, but it often has a 10K ohm value. This is the case for a switch, which has no resistance value of its own.
In the case of sensors like pressure sensors, they have their own basic resistance values, which means a resistor value of less than 10K ohm is needed. For example, for the pressure sensors we sometimes use, a good value for the resistor is 4.8K ohm.
The wiring for turning a two output sensor into a voltage divider network with three wires is as follows:
- the power lead (red) is attached to one terminal of the switch
- the signal (white) is attached directly to the other terminal of the switch
- a 10K ohm resistor is attached to the same terminal of the switch as the signal
- the ground (black) is then attached to the other end of the resistor
The terminals of the switch are equivalent
| switch pole 1: | ——————————– | power (red) ——– | microcontroller |
| switch pole 2: | ——————————– | signal (white) —— | microcontroller |
| \—- 10K ohm resistor —- | ground (black) —- | microcontroller |
Normally, you should use a single pole, single throw (SPST) switch. You can use either a momentary switch or a toggle switch. The momentary switch only makes contact while you depress it. The toggle switch holds it position in either on or off position…

Last modified May 23rd, 2011

