Bird
0
0

Find the mistake in this code that causes the LED not to turn on:

medium📝 Debug Q7 of 15
Raspberry Pi - LED and Button Projects
Find the mistake in this code that causes the LED not to turn on:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT)
GPIO.output(21, 1)
AMissing GPIO.cleanup() at the end
BUsing integer 1 instead of GPIO.HIGH
CPin 21 is not set as input
DGPIO.setmode should be GPIO.BOARD
Step-by-Step Solution
Solution:
  1. Step 1: Check the output signal value

    GPIO.output expects GPIO.HIGH or GPIO.LOW constants, not raw integers.
  2. Step 2: Understand why integer 1 may fail

    Using 1 instead of GPIO.HIGH can cause unexpected behavior or no output.
  3. Final Answer:

    Using integer 1 instead of GPIO.HIGH -> Option B
  4. Quick Check:

    Use GPIO.HIGH/LOW constants, not integers [OK]
Quick Trick: Always use GPIO.HIGH or GPIO.LOW, not 1 or 0 [OK]
Common Mistakes:
  • Using raw integers instead of GPIO constants
  • Forgetting cleanup() (not critical here)
  • Confusing BOARD and BCM modes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes