0
0
Raspberry Piprogramming~20 mins

Pull-up and pull-down resistors in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pull-up and Pull-down Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Reading a button state with pull-up resistor

What will be the output of this Raspberry Pi Python code when the button is not pressed?

Raspberry Pi
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
button_pin = 18
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

state = GPIO.input(button_pin)
print(state)
A1
B0
CRaises RuntimeError
DNone
Attempts:
2 left
💡 Hint

Think about what a pull-up resistor does to the input pin when the button is not pressed.

Predict Output
intermediate
2:00remaining
Reading a button state with pull-down resistor

What will this Raspberry Pi Python code print when the button is pressed?

Raspberry Pi
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
button_pin = 23
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

state = GPIO.input(button_pin)
print(state)
A1
BNone
C0
DRaises RuntimeError
Attempts:
2 left
💡 Hint

Consider what a pull-down resistor does and what happens when the button connects the pin to 3.3V.

🧠 Conceptual
advanced
1:30remaining
Purpose of pull-up and pull-down resistors

Why do we use pull-up or pull-down resistors with input pins on a Raspberry Pi?

ATo make the pin output more current
BTo increase the voltage output of the pin
CTo connect the pin directly to ground
DTo prevent the input pin from floating and reading random values
Attempts:
2 left
💡 Hint

Think about what happens if an input pin is left disconnected.

Predict Output
advanced
1:30remaining
Effect of missing pull resistor on input reading

What is the most likely output of this code if no pull-up or pull-down resistor is set and the button is not connected?

Raspberry Pi
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
button_pin = 17
GPIO.setup(button_pin, GPIO.IN)

state = GPIO.input(button_pin)
print(state)
AAlways 0
BAlways 1
C0 or 1 randomly (floating input)
DRaises RuntimeError
Attempts:
2 left
💡 Hint

Consider what happens to an input pin without a defined voltage level.

🧠 Conceptual
expert
2:00remaining
Choosing pull-up vs pull-down resistor in circuit design

In a Raspberry Pi project, why might you choose a pull-up resistor instead of a pull-down resistor for a button input?

ABecause pull-down resistors consume less power
BBecause the Raspberry Pi GPIO pins have built-in pull-up resistors and it simplifies wiring
CBecause pull-up resistors increase the input voltage beyond 3.3V
DBecause pull-down resistors are not supported by Raspberry Pi
Attempts:
2 left
💡 Hint

Think about the Raspberry Pi hardware features and common wiring practices.