Question 11.6: Using an External Pull-up Resistor You want to run a long wi......

Using an External Pull-up Resistor

You want to run a long wire from the Raspberry Pi to the switch, but you are getting some false readings on the input pin.

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.

The internal pull-up resistors are quite weak (about 40kΩ). So, if you run a long lead to the switch or operate in an electrically noisy environment, you may get false triggerings on the digital input. You can overcome this by turning off the internal pull-up and pulldown resistors and using an external pull-up resistor.

Figure 11-8 shows the use of an external pull-up resistor.

To test out this hardware, you can use the program switch.py; see Recipe 11.1.

Discussion

The lower the resistance of the resistor, the longer the range of your switch. However, when you press the button, a current flows from 3.3V through the resistor to ground. A 100Ω resistor will draw a current of 3.3V/100Ω = 33 mA. This is within the safe limit for the 3.3V supply of 50 mA, so don’t use a lower value than this.

In almost all cases, a 1kΩ resistor will provide a long range with no problems.

See Also

For the basics of connecting a button, see Recipe 11.1.

11.8

Related Answered Questions

Question: 11.13

Verified Answer:

Use an RTC (real-time clock) module. A very common...
Question: 11.8

Verified Answer:

Keypads are arranged in rows and columns, with a p...
Question: 11.2

Verified Answer:

Record the last state of the button and invert tha...
Question: 11.1

Verified Answer:

Connect a switch to a GPIO pin and use the RPi.GPI...
Question: 11.7

Verified Answer:

Use a rotary (quadrature encoder) connected to two...
Question: 11.9

Verified Answer:

Use a PIR (passive infrared) motion detector modul...
Question: 11.12

Verified Answer:

The solution to this is very similar to that of us...
Question: 11.11

Verified Answer:

There are at least two ways to solve this problem....