What Is PWM? Pinouts, Wiring, and Common Errors (2026 Guide)

What Is PWM? Pinouts, Wiring, and Common Errors (2026 Guide)

PWM (Pulse Width Modulation) fakes an analog output from a digital pin that can only ever be fully on or fully off. The pin switches on and off very fast and varies the duty cycle — the percentage of time it spends on — so the average effect looks analog even though every pulse is either 5V or 0V.

Quick answer: PWM switches a pin on/off fast and varies the duty cycle to fake an analog level — 50% averages to half brightness on an LED. On an Arduino Uno, six pins support it: 3, 5, 6, 9, 10, 11, via analogWrite(pin, value), value 0–255. You'll use it most for dimming LEDs and positioning servos.

Proof of work: the explanation and code below are Soldr's actual answer to "What is PWM and how do I use it?", asked through Compoden's AI build assistant on 11 August 2026. Published 11 August 2026 · Last updated 11 August 2026.

Soldr's answer explaining PWM: duty cycle 0/50/100 percent, the six PWM-capable Uno pins, and a servo sweep example
Soldr's build log answering "What is PWM and how do I use it?" — the duty-cycle explanation and a servo-sweep sketch generated in the same session.

What does duty cycle actually mean?

Duty cycle is the percentage of time a PWM pin spends on versus off, and it's the entire mechanism behind everything PWM does. At 0% the pin is always off — 0V average, looks identical to a pin that's simply low. At 100% it's always on — full 5V, same as a plain digital HIGH. At 50%, the pin spends half its time on and half off, which averages to roughly 2.5V — on an LED, that reads as half brightness even though the LED is technically flickering between fully on and fully off far faster than your eye can follow.

PWM at a glance
Property Value
What it fakes An analog voltage level, from a digital on/off pin
Control function analogWrite(pin, value), value 0–255 (0 = 0%, 255 = 100%)
Arduino Uno PWM pins 3, 5, 6, 9, 10, 11 (six of the fourteen digital pins)
Common uses LED dimming, servo positioning, DC motor speed via a motor driver

How do you position a servo with PWM on an Arduino Uno?

A servo reads a specific pulse width — roughly 1ms for 0°, 2ms for 180° — repeated at 50Hz, and moves to whatever angle that pulse width represents. You can drive a servo directly with analogWrite, but it's coarse; the proper way is the Servo library, which handles the exact pulse timing for you with a single call like myServo.write(90).

Wire the servo's signal wire to pin 9, power to 5V, and ground to GND. This is the exact sweep sketch from Soldr's session:

#include <Servo.h>
Servo myServo;

void setup() {
  myServo.attach(9);
}

void loop() {
  for (int angle = 0; angle <= 180; angle++) { myServo.write(angle); delay(15); }
  for (int angle = 180; angle >= 0; angle--) { myServo.write(angle); delay(15); }
}

That sweeps the horn back and forth continuously — your first tangible PWM demo, no serial output needed to see it working.

Why is my servo jittering or not moving smoothly?

The most common cause is powering the servo straight from the Uno's 5V pin while it's also driving other loads — a servo under load can draw more current than the board's regulator comfortably supplies, and the resulting voltage sag causes jitter. For a single small servo like an SG90 this is usually fine, but as you add more servos or heavier ones, move to a separate 5V supply for the servos and keep only the signal wire and a shared ground connected to the Uno. The second common mistake is driving a servo with plain analogWrite instead of the Servo library — it can work, but the pulse timing is coarse and the servo will hunt rather than settle cleanly.

What do you need to try this yourself?

The exact pair from Soldr's session: an Uno R3 CH340G ATmega328P Board (Rs.230, the cheapest variant — standard 5V-logic learning board with six PWM pins) and an SG90 Servo Motor (Rs.120). Total Rs.350 for a working PWM demo with zero extra parts.

Frequently asked questions

PWM se LED ki brightness kaise control karte hain?

PWM pin ko analogWrite(pin, value) se control karke, jahan value 0 se 255 tak hoti hai - 0 matlab bilkul off, 255 matlab pura bright. Beech ki koi bhi value LED ko us duty cycle ke hisaab se dim kar degi, jaise 128 lagbhag aadhi brightness dega.

Can any Arduino Uno pin do PWM?

No - only six of the fourteen digital pins support it: 3, 5, 6, 9, 10, and 11. These are marked with a tilde (~) symbol next to the pin number on most Uno boards. Trying analogWrite on a non-PWM pin won't error, but it will just behave like a plain digital HIGH or LOW instead of a variable output.

What is the price of an SG90 servo motor in India?

The SG90 9g Micro Servo Motor costs Rs.120 at Compoden, with cash on delivery available across India. Paired with an Uno R3 CH340G board (Rs.230), the full PWM starter setup from this guide costs Rs.350. Prices checked 11 August 2026.

Does PWM work the same way on an ESP32 as on an Arduino Uno?

The Servo library call itself is portable — myServo.attach(pin) and myServo.write(angle) work the same way on both. The underlying PWM hardware differs (the ESP32 uses its LEDC peripheral rather than the ATmega328P's timers), but the library hides that difference, so the same sketch generally runs on either board with just the pin number changed.

Back to blog