Pull up & pull-down resistors

6
Pull-up & Pull-down Resistors Often we want to connect a digital input line to our microcontroller. Typically this might be to allow us to monitor the on-off state of a switch. Eg. At first glance this seems fine. When the switch is closed, the pin on our microcontroller is tied to 0 volt, ie. low. switch 0 V (gnd or ) 5 V Microcontr oller

Transcript of Pull up & pull-down resistors

Page 1: Pull up & pull-down resistors

Pull-up & Pull-down Resistors

Often we want to connect a digital input line to our microcontroller. Typically this might be to allow us to monitor the on-off state of a switch.

Eg.

At first glance this seems fine.

When the switch is closed, the pin on our microcontroller is tied to 0 volt, ie. low.

In contrast when the switch is open we would want the pin to be 5 volts, or high.

switch

0 V(gnd or )

5 V

Microcontroller

Page 2: Pull up & pull-down resistors

The input pin would tend to “float” high. This however isn’t a true input signal, it is a very weak input and can readily switch from high to low through the slightest of electrical interference in any of the wiring.

Page 3: Pull up & pull-down resistors

A simple solution might appear to involve simply connecting the other end of the switch to our 5 volt supply

This will give us a 5 volt (high) signal on the input pin when the switch is open. When the switch is closed however we will get a short between supply and ground => zero resistance => infinite current - this is not good news.

switch

0 V(gnd or )

5 V

Microcontroller

Page 4: Pull up & pull-down resistors

The problem can be remedied by simply putting a resistor into the circuit. This is the pull-up resistor.

When the switch is open, the input to the microcontroller is high. There is no direct connection to the 5v rail, however because the input impedence to the microcontroller is high, very little of the 5v is dropped over the pull up resistor.

When the switch is closed current flows down through the resistor and through the closed switch to ground. The input pin is tied to ground and so will read low.

This gives us what we want.

switch

0 V(gnd or )

5 V

Microcontroller

10 k

Page 5: Pull up & pull-down resistors

A variation on this is the pull-down resistor. This ties the input pin to ground rather than the supply voltage.

ie.

switch

0 V(gnd or )

5 V

Microcontroller

10 k