Bird
0
0

You wrote this code to control an LED brightness with PWM on Raspberry Pi but the LED stays fully on:

medium📝 Debug Q14 of 15
Raspberry Pi - PWM Output
You wrote this code to control an LED brightness with PWM on Raspberry Pi but the LED stays fully on:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
pin = 18
GPIO.setup(pin, GPIO.OUT)
pwm = GPIO.PWM(pin, 100)
pwm.start(100)
What is the likely mistake?
AThe pin number 18 is invalid for PWM.
BThe frequency 100 is too low for PWM to work.
CYou forgot to call GPIO.cleanup() before starting PWM.
DThe duty cycle is set to 100%, so the LED is always fully on.
Step-by-Step Solution
Solution:
  1. Step 1: Check the duty cycle value

    The code uses pwm.start(100), which means 100% duty cycle (always on).
  2. Step 2: Understand effect of 100% duty cycle

    At 100% duty cycle, the LED receives full power constantly, so it stays fully on.
  3. Final Answer:

    The duty cycle is set to 100%, so the LED is always fully on. -> Option D
  4. Quick Check:

    100% duty cycle = LED fully on = The duty cycle is set to 100%, so the LED is always fully on. [OK]
Quick Trick: 100% duty cycle means always on [OK]
Common Mistakes:
  • Thinking frequency 100 is too low to work
  • Believing GPIO.cleanup() is needed before PWM start
  • Assuming pin 18 can't do PWM

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes