Skip to content
Stern Didactic GmbH

Knowledge · Electrical and mechatronics

PWM (pulse-width modulation)

Pulse-width modulation is a method in which a voltage is switched on and off rapidly to control a load continuously. What counts is the duty cycle, the share of on-time in the period.

Explanation

A microcontroller can output only two states on a digital pin, on or off. If it switches fast enough, a sluggish load responds to the mean value. A motor cannot follow the switching because of its inductance and inertia, and an LED flickers too fast for the eye to see. At a 50 % duty cycle half the voltage acts, at 25 % a quarter.

The advantage over a series resistor is efficiency. The switch is either fully open or fully closed, so hardly any power is lost. That is why frequency converters and DC choppers in industry also use PWM.

On Arduino, analogWrite() generates the signal. By default the value ranges from 0 (always off) to 255 (always on). Not every pin can do PWM; which ones can is in the board's data sheet. In practice a motor only starts to move above a certain duty cycle because it has to overcome static friction.

Formulas and worked example

Given: analogWrite(pin, 200) at , ideally: ignoring the driver's voltage drop

Guide value; follow the manufacturer’s data.

In practice: Design & Make – Mecanum rover, Control and programming (Arduino Nano 33 IoT)

In the Mecanum rover the PWM signal goes to the motor driver's enable pin, not to the direction pins. The project data explain why: the direction pins need only two states, while the enable pin switches the entire motor current. For joystick control a dead zone of 15 % of full deflection is recommended, and the remaining deflection is mapped not to 0 to 255 but from an experimentally determined starting value of about 80.

To the training project Design & Make – Mecanum rover

Common mistakes

  • Putting PWM on a direction pin. The motor keeps switching between driving and braking, judders and the driver heats up.
  • Using a pin without PWM capability. The signal is then only on or off.
  • Expecting small values to make the motor run slowly. Below the starting value it only hums.

Related offers

Project Design & Make – Mecanum roverWorkshop Design & Make

Sources

Standards are named only; this page does not reproduce their content. As of 18 November 2026.