Bird
0
0

What will be the output of this Python code controlling a pump based on soil moisture sensor reading?

medium📝 Predict Output Q13 of 15
Raspberry Pi - Automation and Scheduling

What will be the output of this Python code controlling a pump based on soil moisture sensor reading?

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
soil_moisture = 300  # sensor value
if soil_moisture < 400:
    GPIO.output(17, GPIO.HIGH)
    print("Pump ON")
else:
    GPIO.output(17, GPIO.LOW)
    print("Pump OFF")
ASyntaxError
BPump OFF
CPump ON
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Check soil moisture condition

    Value 300 is less than 400, so condition is true.
  2. Step 2: Determine pump action and output

    GPIO.output sets pin HIGH and prints "Pump ON".
  3. Final Answer:

    Pump ON -> Option C
  4. Quick Check:

    300 < 400 triggers Pump ON [OK]
Quick Trick: Compare sensor value to threshold to decide pump state [OK]
Common Mistakes:
MISTAKES
  • Misreading the comparison operator
  • Confusing HIGH and LOW states
  • Ignoring print output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes