One-sentence summary
A DC motor turns electrical energy into continuous spinning; to control its speed and direction and to run it safely, we use a motor driver together with a separate power source.
Why does it matter?
We learned about the servo motor in the previous lesson. A servo turns to a specific angle and stops there, which is great for setting the position of an arm or a steering part. But if you want to spin a robot's wheel, you need a motor that keeps turning. That is exactly what a DC motor does.
Toy cars, desk fans, electric toothbrushes and many robot wheels run on DC motors. So almost everyone who starts building robots meets a DC motor at some point.
There is an important safety and engineering point here, though. A DC motor draws far more current than a small LED. If you connect a motor directly to a pin on your micro:bit or Arduino, you can damage the board. In this lesson we will learn why we power the motor separately and what a motor driver is for.
What is a DC motor and how does it work?
What does it do?
A DC motor runs on direct current (DC) and gives the shaft a continuous spinning motion. It has two connection terminals. When you connect a battery, the shaft spins; if you swap the terminals, it spins the other way.
A simple idea of how it spins
Inside there is a magnet and a coil that becomes magnetic when electricity flows through it. As current passes, the coil pushes and pulls against the magnet and turns the shaft. In other words, electrical energy becomes movement. We can sum up the idea like this:
- Higher voltage or more current → usually a faster spin.
- Reversing the terminals → the motor spins the other way.
How it differs from a servo
- Servo: Moves to a set angle and stops (for example 0°–180°). It is for position control.
- DC motor: Keeps spinning. It is for speed and direction control, but on its own it does not tell you "how many degrees I turned."
Two everyday examples
- Toy car: The DC motor inside spins the wheels; connect the battery the wrong way round and the car goes backwards.
- Desk fan: Same idea — a DC motor spins the blades, and a switch changes its speed.
Why don't we power the motor straight from the board?
The current problem
An LED draws very little current, so we can connect it directly to a pin. A DC motor, on the other hand, needs much more current while running, especially at the very start of a spin. The pins on a micro:bit or Arduino cannot supply that much current.
Simple rule: A board's pin is not built to spin a motor. The pin only gives an "order"; the power must come from somewhere else.
If you connect a motor straight to a pin, two bad things can happen: the board cannot supply enough current so the motor barely turns, or the board is overloaded and the pin or board is damaged.
The solution: a motor driver
A motor driver is a helper that takes the small signal from the board and powers the motor from a separate power source. Common classroom examples are boards like the L298N and L9110.
A motor driver does two jobs at once:
- It uses the board's small signal to switch the motor on/off and choose its direction.
- It draws the current the motor needs from a separate power source (such as a battery pack), which protects your board.
Think of it like a tap: your finger nudges a small lever (the signal), but the water that flows comes from the pipe (the separate power). Your finger uses little force, while the water comes from the pipe's pressure.
How are speed and direction controlled?
- Direction: When you tell the driver "forward" or "backward," the driver swaps the terminals on the motor and it spins the other way.
- Speed: With a method called PWM, we switch the power to the motor on and off very quickly. The more it stays "on," the faster the motor spins. Starting at a small percentage and increasing slowly is the safest way.
Pseudocode and example
The pseudocode below shows how we control a motor through a driver. The real pin numbers depend on the board you use.
Start
Set motor power very low (for example 30%)
Choose the forward direction
Spin forward for 2 seconds
Stop the motor
Choose the backward direction
Spin backward for 2 seconds
Stop the motor
End
A micro:bit-style snippet (the logic stays the same):
# We control the motor with a separate power source and a driver
drv = MotorDriver(dir_pin=1, speed_pin=2)
drv.direction("forward")
drv.speed(30) # start at low speed (30%)
sleep(2000) # spin for 2 seconds
drv.stop()
drv.direction("backward")
drv.speed(30)
sleep(2000)
drv.stop() # stop the motor when we are done
Notice that the speed starts low (30%). We always test the motor at low speed and then increase it.
Mini practice
Design a desk-fan behaviour: the motor spins slow, then medium, then fast, then changes direction and stops. Write the pseudocode first, then try it with an adult using a driver and a battery pack.
Start
Direction: forward
Speed 30%, wait 2 seconds
Speed 60%, wait 2 seconds
Speed 90%, wait 2 seconds
Stop the motor
Direction: backward
Speed 40%, wait 2 seconds
Stop the motor
End
Check yourself:
- What speed did you start the motor at? Why is a low speed safer?
- Did you stop the motor before changing direction?
- Is the power source separate, or did you accidentally power it from the board?
Common mistakes
Connecting the motor straight to the board
Wiring the motor directly to a micro:bit or Arduino pin is the most common and most dangerous mistake. Always use a motor driver.
Not separating the power source
If the motor and the board share the same weak source, the board may reset or the motor may not spin. Give the motor its own battery pack.
Starting at high speed
Running the motor at full speed at once can pull cables or send the robot off the table. Start slow and increase gradually.
Changing direction suddenly
Sending a "backward" command while the motor is spinning forward at full speed strains the driver and the motor. Stop first, then set the reverse direction.
Safety note
DC motors are spinning, moving parts. To work safely:
- Keep your fingers, hair and clothes away from the spinning shaft, gears or blades. Tie back long hair.
- Keep cables away from moving parts; they can get tangled.
- Connect the motor through a motor driver; never power it straight from a board pin.
- Take the motor's power from a separate, low-voltage source (a battery pack or USB). Never use mains (wall-socket) electricity.
- Start the motor at low speed, then increase it.
- If cables get hot, or you notice an odd smell or sound, cut the power immediately.
- Do all wiring and testing with an adult present.
Lesson summary
- A DC motor spins continuously, and we can control its speed and direction.
- Reversing the terminals changes the direction; PWM sets the speed.
- A DC motor draws far more current than an LED, so we never power it straight from the board.
- A motor driver takes the board's small signal, powers the motor from a separate source, and protects the board.
- For safety, start at low speed, stay clear of moving parts, and use only a low-voltage source.
Review questions
- What is the most basic difference between a DC motor and a servo motor?
- How do we change the direction in which a motor spins?
- Why don't we connect a DC motor straight to a micro:bit or Arduino pin?
- What are the two main jobs of a motor driver?
- Where should the motor's power come from, and at what speed should we start it?
Answers
- A DC motor spins continuously (speed/direction control); a servo moves to a set angle and stops (position control).
- We reverse the terminals on the motor; the driver's "forward/backward" command does this.
- Because a DC motor draws too much current; the board's pin cannot supply it and the board could be damaged.
- Switching the motor on/off and choosing its direction from the board's signal, and powering the motor from a separate source to supply the needed current.
- From a separate, low-voltage source (a battery pack/USB); we should start the motor at low speed and increase it slowly.
Source and verification note
For “DC Motors and Motor Drivers”, verification focuses on whether the relationship between What is a DC motor and how does it work? and A simple idea of how it spins remains consistent across examples. Sensor readings can change with the model, supply voltage and environment. Thresholds in the lessons are therefore examples; a real project should use a measurement table and calibration.
Next lesson
What Is a Stepper Motor?