Skip to Content
Circuitera

Predict PWM duty cycle before fading an Arduino LED

Use a duty-cycle slider to predict the HIGH time of an Arduino Uno PWM output, then test the prediction on a simulated LED circuit.

0 of 3 complete · Progress saved on this device

Predict the HIGH time

In a period of 10 ms, an output that is HIGH for 2 ms has a 20% duty cycle. Moving the slider changes the HIGH fraction while the period stays fixed. The diagram uses a round period for arithmetic. The real Uno period is set by its timer configuration.

One PWM period
2.0 ms HIGH · 8.0 ms LOW
At 60% duty cycle, how many milliseconds is this 10 ms waveform HIGH?

Translate duty cycle to a byte

The Uno R3 analogWrite input is 0–255. With the default core, D9 supports PWM. Use 64 for roughly one quarter of the range. The output switches between LOW and HIGH, and the diagram does not predict LED brightness perceived by a person.

Fill in the duty argument for roughly a quarter of full scale.

Test D9 and diagnose a steady output

Launch the sketch and run the Uno model with its D9 resistor and LED. Try 0, 64, and 255, rebuilding after edits. If only on and off work in a physical circuit, check the selected pin against the Uno R3 PWM pin list and confirm the resistor and LED are in series. Compare average behavior over multiple periods.

Open the exact Uno example

void setup() {
  pinMode(9, OUTPUT);
  analogWrite(9, 64);
}
void loop() {}

Verified with [email protected] on Uno R3 (2026-12-05 UTC). The matching circuit passed its Uno model checks. This check did not use physical hardware.

Continue learning

Sources