0
0
Raspberry Piprogramming~20 mins

Why PWM is needed for analog-like control in Raspberry Pi - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PWM Mastery on Raspberry Pi
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use PWM for analog-like control on Raspberry Pi?

On a Raspberry Pi, why is Pulse Width Modulation (PWM) used to simulate analog output instead of directly outputting a varying voltage?

ABecause Raspberry Pi GPIO pins can only output digital signals (on/off), PWM creates an average voltage effect by switching rapidly.
BBecause Raspberry Pi GPIO pins can output true analog voltages, PWM is just a simpler alternative.
CBecause PWM reduces the power consumption of the Raspberry Pi by lowering voltage permanently.
DBecause PWM signals are easier to read by sensors than analog voltages.
Attempts:
2 left
💡 Hint

Think about what kind of signals Raspberry Pi pins can produce physically.

Predict Output
intermediate
2:00remaining
PWM Duty Cycle Effect on LED Brightness

What will be the brightness effect on an LED connected to a Raspberry Pi GPIO pin when the PWM duty cycle is set to 75%?

Raspberry Pi
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 1000)  # 1kHz frequency
pwm.start(0)

pwm.ChangeDutyCycle(75)
time.sleep(2)
pwm.stop()
GPIO.cleanup()
AThe LED will be off because 75% duty cycle is too high.
BThe LED will be bright, approximately 75% of full brightness.
CThe LED will blink on and off slowly at 75% intervals.
DThe LED will be at full brightness regardless of duty cycle.
Attempts:
2 left
💡 Hint

Duty cycle controls how long the LED is on during each cycle.

🔧 Debug
advanced
2:00remaining
Why does this PWM code not dim the LED?

Given this Raspberry Pi PWM code, why does the LED stay fully on instead of dimming?

Raspberry Pi
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 1000)
pwm.start(100)

for dc in range(0, 101, 20):
    pwm.ChangeDutyCycle(dc)
    time.sleep(0.5)
pwm.stop()
GPIO.cleanup()
ABecause the GPIO pin was not set up as output, the PWM does not work.
BBecause the PWM was started at 100% duty cycle, the LED stays fully on and the ChangeDutyCycle calls have no effect.
CBecause the PWM was started at 100% duty cycle, the LED starts fully on and the loop changes duty cycle correctly, so the LED dims as expected.
DBecause the frequency is too high, the LED cannot dim.
Attempts:
2 left
💡 Hint

Check how the duty cycle changes inside the loop.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in PWM setup code

Which option contains a syntax error in setting up PWM on Raspberry Pi?

Raspberry Pi
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 1000)
pwm.start(50)
A
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 1000)
pwm.start(50)
B
PIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 1000)
pwm.start(50)
C
)05(trats.mwp
)0001 ,81(MWP.OIPG = mwp
)TUO.OIPG ,81(putes.OIPG
D
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18 1000)
pwm.start(50)
Attempts:
2 left
💡 Hint

Look for missing commas or parentheses.

🚀 Application
expert
2:00remaining
Calculate average voltage from PWM duty cycle

A Raspberry Pi GPIO pin outputs 3.3V when on. If PWM is set to 40% duty cycle, what is the average voltage the connected device experiences?

A1.32 volts
B0.40 volts
C1.98 volts
D3.30 volts
Attempts:
2 left
💡 Hint

Multiply the duty cycle percentage by the voltage when on.