Bird
0
0

You want to blink an LED connected to GPIO pin 23 on Raspberry Pi using Python. Which code snippet correctly blinks the LED once with 1 second ON and 1 second OFF?

hard📝 Application Q8 of 15
Raspberry Pi - Platform
You want to blink an LED connected to GPIO pin 23 on Raspberry Pi using Python. Which code snippet correctly blinks the LED once with 1 second ON and 1 second OFF?
Aimport RPi.GPIO as GPIO GPIO.setup(23, GPIO.OUT) GPIO.output(23, 1) time.sleep(1) GPIO.output(23, 0) time.sleep(1)
Bimport RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(23, GPIO.IN) GPIO.output(23, True) time.sleep(1)
Cimport RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.OUT) GPIO.output(23, True) time.sleep(1) GPIO.output(23, False) time.sleep(1)
Dimport RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.OUT) GPIO.output(23, False) time.sleep(1) GPIO.output(23, True) time.sleep(1)
Step-by-Step Solution
Solution:
  1. Step 1: Verify pin mode and setup

    Pin 23 is set as output with GPIO.setmode(GPIO.BCM) and GPIO.setup(23, GPIO.OUT).
  2. Step 2: Check output and timing for blinking

    Turning pin ON (True), wait 1 second, then OFF (False), wait 1 second correctly blinks once.
  3. Final Answer:

    Code snippet B correctly blinks LED once with 1 second ON and OFF -> Option C
  4. Quick Check:

    Blink LED = setup output, ON, sleep, OFF, sleep [OK]
Quick Trick: Blink LED by toggling output with sleep delays [OK]
Common Mistakes:
  • Missing GPIO.setmode call
  • Setting pin as input instead of output
  • Reversing ON/OFF order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes