PWM and Servo Control
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
| PWM | Generate pulse width modulated signal of digital output pin |
| Pan Tilt Hat | Control pan and tilt motions using PCA9685-based PWM driver (Since R2022a) |
| Standard Servo Write | Set shaft position of standard servo motor to angle specified in degrees |
Objects
servo | Create connection to servo motor |
Functions
writePWMFrequency | Writes PWM frequency to a GPIO pin |
writePWMVoltage | Writes average PWM voltage to a GPIO pin |
writePWMDutyCycle | Writes PWM duty cycle to PWM pin |
writePosition | Write position of servo motor |
Topics
- Raspberry Pi PWM
Raspberry Pi pulse-width modulation (PWM) module.
- Servo Motors
Raspberry Pi servo module.
- Rotate a Servo Motor
This example shows how to rotate a servo motor by its maximum angle.


