DC and geared motors
What you’ll learn
- How a DC motor turns electricity into rotation
- What voltage, speed, torque and stall current mean for a motor
- Why robots use gear motors
How it works
Inside a brushed DC motor, a coil of wire sits between magnets. Current through the coil makes it a magnet too, which pushes and pulls against the fixed magnets and makes it spin. Brushes and a commutator keep switching the current so it keeps turning.
- More voltage → faster (up to the motor’s rating).
- Swap the two wires → it spins the other way.
Speed versus torque
A motor spins fastest with no load. As the load increases it slows and draws more current. Held completely still (stalled) it draws the most current of all, the stall current, and heats up fast.
| Situation | Speed | Current |
|---|---|---|
| No load | Fastest | Lowest |
| Normal driving | Medium | Medium |
| Stalled (blocked) | Zero | Highest: can overheat |
Gear motors
Bare hobby motors spin at thousands of rpm with little torque, which is useless for wheels. A gear motor adds a gearbox. The yellow “TT” motors in many kits have about a 1:48 gearbox and turn at roughly 100–250 rpm on 3–6 V.
Never from a pin
A motor needs far more current than an Arduino pin can give and makes electrical noise. Always drive motors through a motor driver (next lesson), powered from the battery.
Example: choosing a motor
| Need | Choose |
|---|---|
| Small 2WD car | TT gear motors, 3–6 V |
| Heavier robot, more precise | Metal gear motors (e.g. 12 V, 100–300 rpm) with encoders |
| Fast spinning (fan, weapon) | Bare DC motor, no gearbox |
Example: why the robot drifts
Two “identical” motors never spin at exactly the same speed. Give the faster side a slightly smaller value, for example motors(60, 57), or use encoders to correct it automatically.
Try it
In the simulator, each motor value from −100 to 100 is like the voltage you give that motor.
Robot commands
motors(left, right): wheel power, −100 to 100lineLeft(),lineRight():trueover the black linedistance(): cm to the nearest thing ahead (max 200)distanceLeft(),distanceRight(): cm to the sideslinePosition(): where the line is, −1 (left) to 1 (right), ornullmillis(): milliseconds since Runprint(value): show a message belowsetup()runs once;loop()runs 50 times a second
Faster and slowerEasy
Change the speeds and watch how far the robot travels in each 2-second phase.
Compensate a driftMedium
Pretend the right motor is 10% stronger: write motors(60, 66) and watch it curve. Then fix it in code so it drives straight.
Lower the right side by the same amount: motors(60, 60) here, or in general scale the stronger motor down, e.g. motors(60, 66 * 0.91).
Stall dangerHard
A motor’s stall current is 1.5 A, and your motor driver can supply 1 A per channel. What happens if the robot gets stuck against a wall, and how could code protect it? The driver overheats or shuts down. Protect it by stopping when the robot hasn’t moved for a while (e.g. distance unchanged for 1 s, or encoders not counting), and by ramping speed up gradually.
Quick check
Finished this lesson?