Bird
0
0

Which of the following Python code snippets correctly initializes GPIO pin 18 for relay control using RPi.GPIO?

easy📝 Syntax Q3 of 15
Raspberry Pi - Automation and Scheduling
Which of the following Python code snippets correctly initializes GPIO pin 18 for relay control using RPi.GPIO?
AGPIO.setup(18, GPIO.IN)
BGPIO.setup(18, GPIO.OUT)
CGPIO.setup(18, GPIO.PWM)
DGPIO.setup(18, GPIO.ALT)
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct GPIO setup for relay

    Relay control requires output mode, so GPIO.OUT is needed.
  2. Step 2: Check syntax correctness

    GPIO.setup(pin_number, mode) is the correct function call; GPIO.setup(18, GPIO.OUT) is valid.
  3. Final Answer:

    GPIO.setup(18, GPIO.OUT) -> Option B
  4. Quick Check:

    GPIO setup for relay = GPIO.OUT [OK]
Quick Trick: Use GPIO.setup(pin, GPIO.OUT) to control relays [OK]
Common Mistakes:
MISTAKES
  • Setting pin as input
  • Using invalid mode like GPIO.PWM
  • Incorrect function parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes