Bird
0
0

What will be the output of this Python code snippet if no motion is detected by the PIR sensor?

medium📝 Predict Output Q5 of 15
Raspberry Pi - gpiozero Library

What will be the output of this Python code snippet if no motion is detected by the PIR sensor?

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN)

if GPIO.input(18):
    print("Motion!")
else:
    print("Still")
AMotion!
BStill
CRuntime error
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand GPIO.input when no motion

    GPIO.input(18) returns False if no motion is detected.
  2. Step 2: Evaluate the if-else condition

    Since input is False, else block runs printing "Still".
  3. Final Answer:

    Still -> Option B
  4. Quick Check:

    No motion input = False = else block [OK]
Quick Trick: False input means no motion, triggers else block [OK]
Common Mistakes:
  • Assuming input returns None instead of False
  • Confusing output strings
  • Forgetting to set GPIO mode before setup

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes