What if you could control lights and motors so smoothly that no one notices the power is switching on and off?
Why PWM frequency and duty cycle relationship in Raspberry Pi? - Purpose & Use Cases
Imagine you want to control the brightness of a lamp or the speed of a fan using your Raspberry Pi. You try turning the power on and off manually by pressing a button repeatedly to simulate different brightness or speeds.
Doing this by hand is slow, tiring, and very inaccurate. You can't keep a steady rhythm, so the lamp flickers or the fan speed jumps unpredictably. This makes your device behave strangely and wastes your time.
Using PWM (Pulse Width Modulation) with control over frequency and duty cycle lets your Raspberry Pi switch power on and off very fast and precisely. This creates smooth control over brightness or speed without flicker or jerks.
turn_on() sleep(0.5) turn_off() sleep(0.5) # repeat manually
from gpiozero import PWMOutputDevice pwm = PWMOutputDevice(pin=17, frequency=1000) pwm.value = 0.5 # 50% duty cycle
You can smoothly and efficiently control devices like LEDs and motors with precise timing, making your projects professional and reliable.
Controlling the brightness of an LED strip in your room so it dims gently at night and brightens in the morning without any flicker or sudden jumps.
Manual switching is slow and inconsistent.
PWM frequency controls how fast the power cycles on and off.
Duty cycle controls how long the power stays on in each cycle, affecting brightness or speed.