Main Content

PWM and Servo Control

R2026b
Control pulse width modulated signals and servo motors on Raspberry Pi® hardware

Configure blocks and MATLAB® objects to generate PWM signals and control standard servo motors on Raspberry Pi hardware. Set PWM output for devices like LEDs, motors, and actuators, or precisely position servo motors using pan tilt hat for interactive application-based examples.

Blocks

Raspberry Pi PWM block iconPWMGenerate pulse width modulated signal of digital output pin
Raspberry Pi Pan Tilt Hat iconPan Tilt HatControl pan and tilt motions using PCA9685-based PWM driver (Since R2022a)
Standard Servo Write blockStandard Servo WriteSet shaft position of standard servo motor to angle specified in degrees

Objects

servoCreate connection to servo motor

Functions

writePWMFrequencyWrites PWM frequency to a GPIO pin
writePWMVoltageWrites average PWM voltage to a GPIO pin
writePWMDutyCycleWrites PWM duty cycle to PWM pin
writePositionWrite position of servo motor

Topics

Featured Examples