Experiment
Build a motor that won't stop
Magnets pushing and pulling, switched at just the right moment. Build it wrong first: switch it on and watch it get stuck. Then keep it spinning yourself.
From the Short "Why Doesn't an Electric Motor Just Stop?". ▶ Watch the Short
Switch it on
Two fixed magnets, north facing south. Between them, an iron arm wrapped in wire. Send a current through the wire and the arm becomes a magnet too: an electromagnet.
Switch on the current and watch what the arm does.
Flip it yourself
Flip the current and the arm's ends swap, north for south. The magnet that was pulling it now pushes it, and the one ahead pulls it on.
Keep it spinning for 5 turns. Turns so far: 0
Tip: flip just as the arm lines up with the arrows. You can also press Space. If it stops, drag the arm to get it swinging.
Let the split ring flip it
On the shaft sits a copper ring cut in two: the commutator. Two springy contacts, the brushes, press on it. Every half turn the gaps pass them and the current swaps by itself.
Now park the arm at the dead spot: exactly lined up, where the push is zero. Then drag the arm to give it a flick.
Real motors: three coils
With three coils, one is always well placed to push, so it should start from anywhere and push smoothly.
Here it's parked at the dead spot with one coil. Switch to three coils, and compare the push chart.
What's going on
Opposite ends of magnets pull together and matching ends push apart. A current in a coil of wire makes the coil a magnet, with a north end and a south end, and the iron inside makes it much stronger. Reverse the current and its ends swap.
With the current on and nothing else, the arm swings until its north end faces the fixed south. Lined up like that there's no turning push left, so it wobbles and settles, like a compass needle. That's step 1.
To keep it turning, the current has to flip each time the arm lines up. You did that by hand in step 2. A motor does it with a commutator: a split copper ring on the shaft, with two brushes pressing on it. Every half turn the gaps pass the brushes and the current swaps by itself. The switch comes at about the line-up, where the push drops to zero, and the arm's swing carries it past.
One coil has a weak spot: parked exactly lined up, it gets no push either way, so it can't start. Real motors use three or more coils, so one is always well placed to push. Many modern motors swap the brushes for a chip that does the switching, but underneath it's still magnets pushing and pulling.
Simplified: the fixed magnets are drawn as two blocks (small motors usually have two curved magnets round the arm), the three-coil motor is drawn as three arms that each switch at their own line-up, and the speed is slowed down so you can see it.