Why motors are not like LEDs
A microcontroller output pin can usually supply only a small current, enough for an LED but not for a motor. A motor is a coil and a mechanism: when it starts or stalls it can draw many times its steady running current, and when power is cut it can push voltage spikes back into the circuit. Connecting one straight to a pin can damage the board. This is why motors need driver circuits, and why the motor usually has its own power source.
Work at low voltage while you learn, wear eye protection, and keep fingers, hair and loose clothing away from moving parts. Small motors can pinch or throw a part, and batteries that supply them can overheat if shorted. Do not use mains-powered motors for learning projects, and leave any mains wiring to a qualified professional.
The main motor types
DC motors
A simple brushed DC motor spins when you apply voltage. Higher voltage generally means higher speed, and reversing the polarity reverses the direction. It has no built-in way to know its position, so it is good for wheels, fans and pumps where exact angle does not matter. Many small hobby motors are paired with a gearbox, which trades speed for torque. Check the voltage and current ratings printed on the motor or listed by the seller.
Hobby servos
A hobby servo is a motor plus gears, a position sensor and control electronics in one case. You send it a repeating control pulse, and the width of the pulse tells it which angle to move to. Typically these servos cover a limited range of rotation, often around half a turn, though models vary. Continuous-rotation versions are modified to spin instead, with the signal setting speed and direction. Servos suit steering, arms, grippers and small mechanisms.
Even though the control signal is a low-power pin signal, the servo’s motor needs its own supply and can draw a lot of current when moving or holding a load. Many unexplained resets in beginner projects come from powering servos from the same weak supply as the microcontroller.
Stepper motors
A stepper moves in fixed increments as its coils are energized in sequence. You can count steps to know roughly where it is without a sensor, which is why steppers appear in printers and positioning mechanisms. They need a dedicated driver that handles the coil sequencing and current, and they can get warm when holding a position. They are more complex to set up than a plain DC motor, so most first robots start with DC motors or servos.
What a driver circuit does
A driver sits between the microcontroller and the motor. It takes a small control signal and switches a larger current from a separate supply.
- A single transistor can switch one DC motor in one direction. This is the principle behind a transistor switch, where a small signal controls a bigger load.
- An H-bridge uses four switches arranged so current can flow through the motor either way. That lets you reverse direction, and many ready-made driver boards contain one or two H-bridges.
- Dedicated stepper drivers manage coil timing and current limiting.
- Servos have the driver built in, so you only provide the signal and adequate power.
Protecting the circuit
Because a motor is a coil, switching it off can produce a voltage spike. A diode placed across the motor, called a flyback or freewheel diode, gives that energy a safe path. Many driver boards include this protection already, but if you are building your own circuit with a single transistor, it is something you add. Understanding passive components such as diodes and capacitors helps here, since a capacitor placed close to a motor can reduce electrical noise that disturbs the controller.
Other habits that avoid trouble:
- Connect the grounds of the motor supply and the controller so the control signal has a common reference.
- Fuse or limit the supply where practical, so a stall or short does not cause overheating.
- Keep wiring tidy and secure, because loose motor wires cause intermittent faults.
Controlling speed and direction
Speed of a DC motor is commonly controlled with pulse width modulation, abbreviated PWM. The controller switches the output on and off very quickly, and the proportion of time it is on changes the average power delivered. A higher proportion means a faster motor. Direction comes from the H-bridge inputs. Because small motors often will not turn at very low settings, you may find a minimum value below which the motor only hums.
For servos, you supply the control pulse the servo expects, and a library or built-in function on most microcontroller boards handles that for you. Reading the servo’s documentation avoids damage from driving it past its mechanical limits.
Power planning
Add up what your motors might draw, including stall current, and make sure the supply can handle it. A project power supply for motors often needs to be separate from the one for logic, or at least be large enough that voltage does not sag when motors start. Batteries should be fresh and rated for the current you need. Check connections and warmth before leaving anything unattended, and follow good battery storage practice for spare cells.
Testing in stages
Test the motor on its own with a suitable supply, then test the driver without the mechanical load, then add the load. If something behaves oddly, measure voltages while the motor runs, using a multimeter and the habits described under circuit troubleshooting. Raise the speed slowly, and keep a hand near the power switch the first few times.
These steps lead directly to the small wheeled robots many makers build next. A hobby robot depends on reliable motor drive more than on anything fancy in the code.