The basic working of a motor is based on the fact that when ‘a current carrying conductor is placed in a magnetic field, it experiences a force’.
If you take a simple DC motor, it has a current-carrying coil supported in between two permanent magnets (opposite pole facing) so that the coil can rotate freely inside. When the coil ends are connected to a DC source then the current will flow through it and it behaves like a bar magnet, as shown in Figure 1.
As the current starts flowing, the magnetic flux lines of the coil will interact with the flux lines of the permanent magnet.
This will cause a movement of the coil (Figures 1a, 1b, 1c, 1d) due to the force of attraction and repulsion between two fields. The coil will rotate until it achieves the 180° position, because now the opposite poles will be in front of each other (Figure 1e) and the force of attraction or repulsion will not exist.
The role of the commutator: The commutator brushes just reverse the polarity of DC supply connected to the coil. This will cause a change in the direction of the current of the magnetic field and start rotating the coil by another 180° (Figure 1f).
Similarly, the AC motor also functions on the above principle; except here, the commutator contacts remain stationary, because AC current direction continually changes during each half-cycle (every 180°).
Resource: Practical Troubleshooting of Electrical Equipment and Control Circuits – M. Brown
(Get it from Amazon)