All of our examples so far show  and use an internal pullup.

There are also internal pull down resistors on many microcontroller inputs. In this case you connect your switch's non-digital-pin to Vcc instead of Ground. Vcc might be 5V or 3.3V depending on the 'logic level' of your microcontroller.

But what if your microcontroller does not have an internal pullup or pulldown?

No worries! You can use an external resistor!

Connect one end to the same microcontroller input pin you use for the switch, and the other end to the positive voltage (usually 5 or 3.3 volts). Resistors can be connected either way, they are not polarized so you cannot make the connections "backwards".

The value of the resistor is not usually critical. any resistor between 1,000 ohms (1 KΩ) and 100,000 ohms (100KΩ) should work. If the resistor is too small, you may waste current pushing the button. If too large, the pull up effect may be so weak as to not be detected by the pin electronics. 

A value of 10,000 ohms (10KΩ) or so is a good value and has become a standard for pull up resistors. That's why you'll see so many of them.

You can buy resistors nearly everywhere or find them in salvaging old, unused electronics.

Or you can get them at the Adafruit shop

Angled shot of 25 Through-Hole Resistors - 10K ohm 5% 1/4W.
ΩMG! You're not going to be able to resist these handy resistor packs! Well, axially, they do all of the resisting for you!This is a 25 Pack of 10K...
In Stock

Wiring Example



Above, an external 10K ohm resistor is connected between the microcontroller pin used (#2 pin) and Vcc, which is +5 volts for this board (5V pin). The switch (a push button in this vase) has one connection to ground, another to the resistor and the microcontroller pin. 

The microcontroller pin, if read in code, should be HIGH if the switch is not pressed, LOW if the switch is pressed. 

This method can be used for nearly any type of digital circuit looking for a high or low depending on a switch state.

This guide was first published on Aug 15, 2018. It was last updated on 2018-08-15 12:39:03 -0400.

This page (If Your Microcontroller Doesn't Have Internal Resistors) was last updated on Jun 29, 2018.

Text editor powered by tinymce.