Simulator

A DC motor simulator: a transistor, a diode and a PWM pin

Mokxi is a free online DC motor simulator that runs in your browser, with nothing to install and no account needed. An Arduino Uno ramps a PWM pin up and down, a 2N2222 transistor switches the motor’s current from the 5 V rail, and a 1N4007 diode sits across the motor. The shaft on the canvas speeds up and slows down with the duty cycle, about four seconds per cycle.

  • 455parts on the bench
  • 43boards running now
  • 1.00xreal time, on every board
Arduino Uno: a motor on a transistorlive0.000 s 0.00x
Click to open it in the editor
Watch the shaft speed up and slow down with the PWM, or 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 the motor’s speed follow the PWM duty cycle
  • Put a meter in the motor’s supply and read its current, slow and at speed
  • Change the motor’s rated voltage, speed, winding resistance and inertia
  • Run it forward and back with an H-bridge, or with two relays
  • Swap the 2N2222 for a logic-level MOSFET
  • Edit the Arduino code and press Run again

What the running circuit shows

A pin’s 20 mA, turned into hundreds.

Pin 9 drives the transistor’s base through 1 k, and the transistor sinks the motor’s current to ground. The sketch steps the duty cycle five counts every 40 ms, 0 to 255 and back, and prints “duty 50 / 255”, “duty 100 / 255” and so on as it passes. The pin switches 490 times a second and the motor’s inertia averages that into a speed, which in the engine climbs to about 149 rpm at full duty, a little over two seconds in.

The transistor’s current shows why the pin cannot do this alone. While the motor is still slow each pulse pulls about 390 mA, because a slow motor is little more than its 6 ohm winding and the transistor’s gain has fallen at that current; at full speed its back EMF has risen and the current falls to about 160 mA. A board pin is good for about 20 mA.

How the motor is modeled

Resistance, back EMF and a lag.

The motor is the standard brushed-motor model: the winding resistance in series with a back EMF that grows with speed, and a speed that chases the applied voltage with a first-order lag. Its rating is a small yellow gearbox motor’s, 6 V and 200 rpm, which is why 5 V, less what the transistor and the winding drop, brings it to about 149 rpm. Change the voltage, rpm, resistance or inertia and the same circuit runs a different motor.

What it leaves out: the winding has no inductance, so there is no kick when the current stops. In the engine the collector never rises above the 5 V rail, diode or no diode, where on a bench that kick is what kills a transistor with no diode across the motor. Keep the diode anyway: a circuit that runs cleanly here without one is not safe on real hardware. There is no load on the shaft, no friction and no stall dead band either.

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.

Can I change the motor’s direction?

Not with one transistor, which only switches the current on and off. For forward and reverse use an H-bridge: the motor driver simulator runs one on an L298N, and the parts bin has the L293D, the TB6612 and the L9110 as well.

Why does my motor not spin from an Arduino pin?

A pin gives about 20 mA and a small motor wants hundreds, more to start. Wired straight to a pin it barely turns, here as on a bench. Put a transistor or a driver between them, as in the circuit above.

Do I need a flyback diode?

On real hardware, yes: across every motor and relay coil, band toward the positive side. Mokxi’s motor has no winding inductance, so leaving the diode out shows no symptom here; the flyback diode page puts a coil that does kick on the scope.

Spin a motor

Open the circuit, press Run and watch the shaft. Nothing to install, and no account needed.