Bird
0
0

Which Python code correctly turns ON the fan and turns OFF the light?

hard🚀 Application Q15 of 15
Raspberry Pi - Automation and Scheduling
You want to control two relays connected to GPIO pins 5 and 6 to turn ON a fan and a light respectively. The relays are active LOW. Which Python code correctly turns ON the fan and turns OFF the light?
AGPIO.setup(5, GPIO.OUT) GPIO.setup(6, GPIO.OUT) GPIO.output(5, GPIO.HIGH) GPIO.output(6, GPIO.HIGH)
BGPIO.setup(5, GPIO.OUT) GPIO.setup(6, GPIO.OUT) GPIO.output(5, GPIO.HIGH) GPIO.output(6, GPIO.LOW)
CGPIO.setup(5, GPIO.IN) GPIO.setup(6, GPIO.IN) GPIO.output(5, GPIO.LOW) GPIO.output(6, GPIO.HIGH)
DGPIO.setup(5, GPIO.OUT) GPIO.setup(6, GPIO.OUT) GPIO.output(5, GPIO.LOW) GPIO.output(6, GPIO.HIGH)
Step-by-Step Solution
Solution:
  1. Step 1: Setup pins 5 and 6 as outputs

    Both pins must be outputs to control relays: GPIO.setup(5, GPIO.OUT) and GPIO.setup(6, GPIO.OUT).
  2. Step 2: Apply active LOW logic for relays

    To turn ON the fan (pin 5), output LOW; to turn OFF the light (pin 6), output HIGH.
  3. Final Answer:

    Setup pins as output, output LOW on 5, HIGH on 6 -> Option D
  4. Quick Check:

    Active LOW ON = LOW, OFF = HIGH [OK]
Quick Trick: Active LOW ON means output LOW, OFF means HIGH [OK]
Common Mistakes:
MISTAKES
  • Setting pins as input instead of output
  • Reversing HIGH and LOW for active LOW relay
  • Turning both devices ON or OFF incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes