Simulator

A PWM simulator: a pin that switches 490 times a second

Mokxi is a free online PWM simulator that runs in your browser, with nothing to install and no account needed. An Arduino Uno breathes an LED on pin 9 with analogWrite. The pin is never half on: it switches between 0 and 5 V hundreds of times a second, and the share of each cycle it spends high is what you see as brightness.

  • 505parts on the bench
  • 45boards running now
  • 1.00xreal time, on every board
Arduino Uno: a breathing LEDlive0.000 s 0.00x
Click to open it in the editor
The LED fades up and down about every two seconds. Click the circuit to open it in the editor.

What you can do here

In the circuit above, or in the editor it opens.

  • Watch an LED fade with analogWrite, from 0 to 255
  • Clip the oscilloscope to pin 9 and see the square wave change width
  • Change the breathing table or the step time and run it again
  • Turn a knob to set the duty cycle, in the potentiometer simulator
  • Drive a motor, a servo or an RGB LED from the same PWM pins
  • Save the circuit and share it with one link

What the running circuit shows

A digital pin, standing in for an analog one.

analogWrite does not make a voltage between 0 and 5 V. It sets timer 1 switching pin 9 on and off by itself, and the value from 0 to 255 is how much of each cycle the pin stays high: the duty cycle. 128 is high about half the time, 250 almost all of it. The LED is switched faster than an eye can follow, so it looks steady and dimmer.

In the engine pin 9 rises 49 times in every 100 ms: 490 Hz, which is the Uno’s 16 MHz clock divided by a prescaler of 64 and a phase-correct count of 510. The sketch steps through a 64-entry table every 30 ms, so one breath takes 1.92 seconds, dark at the bottom and brightest in the middle.

How PWM is simulated

The chip’s own timers, not an average.

The Uno’s ATmega328P runs the compiled sketch instruction by instruction, timers included, so the PWM on a pin is the timer’s own output at its real frequency. That is why pins 5 and 6 run at about 980 Hz while pins 3, 9, 10 and 11 run at about 490: timer 0 counts a different way. The LED part follows the current through it, so its brightness tracks the duty cycle.

What it leaves out: the edges are clean, with none of the ringing a real scope shows on a long wire. A pin is not a perfect source, though, here or on the bench: while it is high, the lit LED pulls pin 9 down to about 4.6 V. To turn PWM into a steady voltage, put an RC filter after the pin.

How it works

Three steps from a blank tab to a running circuit.

  1. Open the editor

    It runs in your browser tab. Nothing to install, and you need no account to start.

    Your first project
  2. Wire it and write the code

    Drag parts onto a breadboard, run each wire from pin to pin, and write the sketch beside it.

    Wiring
  3. Press Run

    Your sketch compiles in the tab and runs on a model of the chip, with the Serial Monitor beside it.

    Run and serial
Reviews

What makers say about Mokxi.

“The AI checker helps check and correct my circuits, and it has way more components than Tinkercad. As a student I really appreciate the tool.”

ChloeEngineering student

“I’d been looking for a real online electronic simulator that was intuitive and complete when I found Mokxi. I was able to quickly import a Fritzing file and my Arduino sketch and start testing. Mokxi has all of the makings for the best online Arduino simulator I have been able to find!”

JayModel builderFeatured in his DioramaOS post

“I’m using Mokxi to develop and simulate an STM32-based four-wheel-drive robot car before building the actual hardware. It allows me to experiment with DC motor control, PWM, RPM measurement using photointerrupters, and different acceleration, braking, and reversing strategies, helping me understand and refine the system before implementing it in real life.”

NusretRobot car builder, Hamburg

Share your story

FAQ

Questions, answered.

Is it free?

Yes. The circuit on this page, every part in it and the editor it opens in are on the free plan, with no card.

Do I need an account?

No. The circuit runs the moment the page does, and the editor opens without one. A free account is only for saving a project to the cloud and sharing it by link.

What PWM frequency does an Arduino Uno use?

About 490 Hz on pins 3, 9, 10 and 11, and about 980 Hz on pins 5 and 6, which run from timer 0. The simulator gives both, because it runs the same timers.

What is duty cycle?

The share of each cycle a PWM pin spends high. analogWrite(pin, 64) is a quarter, 128 about half and 255 all of it. Filter the pin with a resistor and a capacitor and you get a voltage that follows the duty cycle.

Can I see the PWM signal?

Yes. Add the oscilloscope from the parts bin, put its probe on pin 9 and its ground on GND, and the square wave widens and narrows as the LED breathes.

More simulators

Each one opens on a circuit that is already running.

See PWM for yourself

Open the circuit, change a number in the table and press Run. Nothing to install, and no account needed.