Bird
0
0

What will be the output of this Python code controlling a relay on GPIO pin 23? import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.OUT) GPIO.output(23, GPIO.HIGH) print(GPIO.input(23))

medium📝 Predict Output Q4 of 15
Raspberry Pi - Automation and Scheduling
What will be the output of this Python code controlling a relay on GPIO pin 23? import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.OUT) GPIO.output(23, GPIO.HIGH) print(GPIO.input(23))
AGPIO.HIGH
B0
C1
DError: GPIO.input() not allowed on output pin
Step-by-Step Solution
Solution:
  1. Step 1: Understand GPIO.output and GPIO.input behavior

    Setting GPIO.output(23, GPIO.HIGH) sets pin 23 to high voltage (logical 1).
  2. Step 2: Reading pin state with GPIO.input

    GPIO.input(23) returns the current state of the pin, which is 1 after setting it high.
  3. Final Answer:

    1 -> Option C
  4. Quick Check:

    GPIO.input after GPIO.output HIGH = 1 [OK]
Quick Trick: GPIO.input reads pin state even if set as output [OK]
Common Mistakes:
MISTAKES
  • Expecting 0 after setting HIGH
  • Thinking GPIO.input causes error
  • Confusing GPIO.HIGH with integer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes