Source: https://mokxi.com/pwm-simulator

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.

Start building free or read how PWM works

- 455 parts on the bench
- 43 boards running now
- 1.00x real time, on every board

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.

What PWM is PWM to an analog voltage Fade an LED with PWM The potentiometer simulator

## Questions

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.

Online circuit simulator Breadboard simulator ESP32 simulator Op-amp simulator Logic gate simulator LED circuit simulator Servo simulator LCD simulator OLED simulator NeoPixel simulator 7 segment display simulator LED matrix simulator Stepper motor simulator Motor driver simulator Ultrasonic sensor simulator Rectifier simulator Digital circuit simulator Potentiometer simulator Relay simulator Shift register simulator DHT11 simulator RFID simulator Accelerometer simulator RGB LED simulator Buzzer simulator MOSFET simulator Circuit simulator for kids Flip-flop simulator Multiplexer simulator Full adder simulator I2C simulator UART simulator Thermistor simulator PIR sensor simulator Oscilloscope simulator Multimeter simulator DC motor simulator Traffic light simulator Diode simulator Capacitor simulator Series and parallel circuit simulator Wheatstone bridge simulator Voltage regulator simulator Soil moisture sensor simulator Zener diode simulator Solar panel simulator AC circuit simulator Thevenin simulator Decoder simulator Encoder simulator PID simulator Robot arm simulator Load cell simulator IR sensor simulator LM35 simulator HC-05 Bluetooth simulator nRF24L01 simulator

## See PWM for yourself

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

Start building free Open the editor
