Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
Raspberry Pi - GPIO Basics with Python
What will be the output of this code?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
print(GPIO.input(23))

Assuming pin 23 is not connected to anything.
ARandom value (0 or 1)
B1
CError: Pin not connected
D0
Step-by-Step Solution
Solution:
  1. Step 1: Understand floating input pins

    If an input pin is not connected (floating), it can randomly read 0 or 1 due to electrical noise.
  2. Step 2: Predict the output

    Since no pull-up or pull-down resistor is set, the value is unpredictable and can be 0 or 1.
  3. Final Answer:

    Random value (0 or 1) -> Option A
  4. Quick Check:

    Floating input pin reads random value [OK]
Quick Trick: Floating input pins read random 0 or 1 without resistor [OK]
Common Mistakes:
  • Expecting fixed 0 or 1
  • Assuming error on unconnected pin

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes