What is PWM and why is it useful in controlling devices with Raspberry Pi?
PWM stands for Pulse Width Modulation. It lets you control the power delivered to devices like LEDs or motors by switching the power on and off very quickly. This way, you can make an LED dim or a motor run at different speeds without changing the voltage.
Click to reveal answer
beginner
How do you set up a GPIO pin for software PWM using RPi.GPIO?
First, import RPi.GPIO and set the mode (e.g., BCM). Then, set the pin as an output using GPIO.setup(pin, GPIO.OUT). Finally, create a PWM object with GPIO.PWM(pin, frequency) where frequency is in Hertz.
Click to reveal answer
beginner
What does the start() method do in RPi.GPIO PWM?
The start() method begins the PWM signal on the pin with a given duty cycle (percentage of time the signal is ON). For example, start(50) means the signal is ON half the time and OFF half the time.
Click to reveal answer
beginner
How can you change the brightness of an LED using software PWM?
You change the duty cycle of the PWM signal. A higher duty cycle means the LED is ON longer in each cycle, making it brighter. A lower duty cycle means it is ON less, making it dimmer.
Click to reveal answer
beginner
Why should you call stop() and cleanup() when you finish using PWM with RPi.GPIO?
stop() stops the PWM signal on the pin, and cleanup() resets all GPIO pins to their default state. This prevents unwanted signals and frees the pins for other uses.
Click to reveal answer
What does PWM stand for?
APower Wave Management
BPower Width Modulation
CPulse Wire Method
DPulse Width Modulation
✗ Incorrect
PWM means Pulse Width Modulation, a technique to control power by switching on and off quickly.
Which RPi.GPIO method starts the PWM signal on a pin?
Apwm.start()
BGPIO.start()
CGPIO.begin()
Dpwm.begin()
✗ Incorrect
The start() method is called on the PWM object to begin the signal.
What does a 75% duty cycle mean for an LED controlled by PWM?
ALED is on 75% of the time
BLED brightness is 25%
CLED blinks 75 times per second
DLED is off 75% of the time
✗ Incorrect
A 75% duty cycle means the LED is ON 75% of the time, making it brighter.
Why do you call GPIO.cleanup() after using PWM?
ATo start PWM again
BTo reset pins and avoid conflicts
CTo increase PWM frequency
DTo save power
✗ Incorrect
cleanup() resets GPIO pins to default, preventing conflicts with other programs.
Which frequency unit is used when creating a PWM object in RPi.GPIO?
ASeconds
BMilliseconds
CHertz
DVolts
✗ Incorrect
Frequency for PWM is given in Hertz (cycles per second).
Explain how to set up and start software PWM on a Raspberry Pi GPIO pin using RPi.GPIO.
Think about the steps from preparing the pin to starting the PWM signal.
You got /4 concepts.
Describe how changing the duty cycle affects an LED's brightness when using software PWM.
Relate duty cycle to how long the LED is powered in each cycle.
You got /3 concepts.
Practice
(1/5)
1. What does Software PWM using RPi.GPIO.PWM allow you to control on a Raspberry Pi?
easy
A. The temperature of the Raspberry Pi CPU
B. The file system permissions on the Raspberry Pi
C. The network speed of the Raspberry Pi
D. The brightness of LEDs or speed of motors by switching pins on and off quickly
Solution
Step 1: Understand what PWM controls
PWM (Pulse Width Modulation) controls how long a pin stays on versus off, affecting devices like LEDs or motors.
Step 2: Identify the effect of switching pins fast
Switching pins on and off quickly changes brightness or speed smoothly.
Final Answer:
The brightness of LEDs or speed of motors by switching pins on and off quickly -> Option D
Quick Check:
Software PWM controls brightness/speed = B [OK]
Hint: PWM controls brightness or speed by fast switching [OK]
Common Mistakes:
Confusing PWM with CPU or network control
Thinking PWM changes file permissions
Assuming PWM controls temperature
2. Which of the following is the correct way to start PWM on pin 18 with a frequency of 1000 Hz using RPi.GPIO?
easy
A. pwm = GPIO.PWM(1000, 18); pwm.start(50)
B. pwm = GPIO.PWM(18); pwm.start(1000)
C. pwm = GPIO.PWM(18, 1000); pwm.start(50)
D. pwm = GPIO.PWM(18, 50); pwm.start(1000)
Solution
Step 1: Check PWM constructor parameters
The PWM constructor takes pin number first, then frequency in Hz, so GPIO.PWM(18, 1000) is correct.
Step 2: Verify start method usage
The start method takes duty cycle percentage, so pwm.start(50) starts PWM at 50% duty cycle.
Final Answer:
pwm = GPIO.PWM(18, 1000); pwm.start(50) -> Option C
Quick Check:
Pin, frequency order + start with duty cycle = A [OK]
Hint: PWM(pin, freq), then start(duty cycle) [OK]
Common Mistakes:
Swapping frequency and pin arguments
Passing duty cycle to PWM constructor
Using start() with frequency instead of duty cycle
3. What will be the output on the LED connected to pin 12 after running this code snippet?