The Raspberry Pi cannot drive an electric motor directly from its GPIO header. The 3.3V logic pins on a Raspberry Pi 4 or 5 are limited to 16mA per pin and roughly 50mA per bank, meaning any attempt to pull a motor's inductive load directly will instantly fry the SoC. To safely interface a raspberry pi electric motor setup, you must use a dedicated motor driver that accepts 3.3V logic while switching higher motor voltages (typically 6V to 24V). But before you wire up a driver, you have to pick the right motor architecture for your specific mechanical load.

The Raspberry Pi Electric Motor Matrix: Choosing Your Drive

Not all motors behave the same way under load, and the Raspberry Pi requires different control strategies for each. Below is a data-dense comparison of the four most common motor types used in Pi-based embedded projects, detailing their torque profiles, control requirements, and 2026 market pricing.

Motor Type Torque Curve Profile RPi Control Needs Typical Cost (2026) Best Application
Brushed DC Gearmotor Peak torque at stall (0 RPM); drops linearly as speed increases. 2x PWM pins (speed) + 4x GPIO (direction/enable) via H-bridge. $8 - $35 Mobile rovers, conveyor belts, winches.
NEMA 17 Stepper Flat, high holding torque up to mid-speed; drops sharply past 300 RPM. STEP/DIR pulses (requires real-time co-processor or UART driver like TMC2209). $15 - $45 CNC routers, 3D printers, precise linear actuators.
RC Servo (e.g., MG996R) High peak torque at stall; zero continuous torque at speed (positional only). 1x 50Hz PWM pin per servo (or I2C PCA9685 board for multiples). $12 - $30 Robotic arms, pan/tilt camera gimbals, steering linkages.
BLDC Outrunner High torque-to-weight ratio; requires electronic commutation to start. 3-phase ESC controlled via 50Hz-400Hz PWM or I2C telemetry. $45 - $120 Drones, high-speed reconnaissance rovers, marine thrusters.
Bench Tip: Avoid the ubiquitous L298N motor driver for modern Raspberry Pi projects. The L298N uses bipolar junction transistors (BJTs) that drop up to 2.5V across the H-bridge and strictly require 5V logic. Instead, use the TB6612FNG (for brushed DC) or DRV8833. They use MOSFETs, drop only ~0.5V, and natively accept the Pi's 3.3V logic without level shifters.

Sizing Your Motor: A Worked Load Example for a 5kg Rover

A common mistake in embedded robotics is converting motor wattage or horsepower without considering the physical load context. Wattage tells you about thermal capacity, not whether the motor can actually push your chassis up a ramp. For mobile robots, we size based on stall torque and no-load RPM.

The Sizing Rule of Thumb: For a wheeled mobile robot operating on mixed indoor surfaces (hard floor and low-pile carpet), calculate the baseline torque required to move the mass, then apply a 2.0x safety factor to account for static friction breakaway, carpet deformation, and minor inclines.

Worked Load Example

Let's size a drive motor for a 5kg (approx. 11 lbs) autonomous rover with 60mm diameter drive wheels (radius = 0.03 meters).

  1. Calculate Force: Force (Newtons) = Mass (kg) × Gravity (9.81 m/s²).
    F = 5 kg × 9.81 = 49.05 N
  2. Calculate Total Torque: Torque (Nm) = Force × Wheel Radius.
    T = 49.05 N × 0.03 m = 1.47 Nm
  3. Split Across Drive Wheels: Assuming a 2-wheel drive (2WD) configuration, divide by 2.
    1.47 Nm / 2 = 0.735 Nm per wheel
  4. Apply Safety Factor: Multiply by 2.0 for carpet friction and incline breakaway.
    0.735 Nm × 2.0 = 1.47 Nm required stall torque per motor

The Selection: We need a motor with at least 1.47 Nm (approx. 15 kg-cm) of stall torque. A standard cheap 'TT' yellow gearmotor only produces about 0.8 Nm and will stall on carpet. Instead, we select a 12V DC Planetary Gearmotor with a 50:1 reduction (such as those available from Pololu or DigiKey), which typically yields 2.0 Nm of stall torque and a no-load speed of 60 RPM. This gives us the necessary breakaway torque while keeping the top speed at a manageable 0.18 meters per second for indoor navigation.

Wiring the TB6612FNG to Raspberry Pi 5: Terminals and Pinout

Now that we have a 12V Brushed DC Gearmotor, we need to wire it to the Raspberry Pi 5 using a TB6612FNG dual motor driver. This chip handles 1.2A continuous current per channel (3.2A peak) and operates on logic voltages from 2.7V to 5.5V, making it a perfect native match for the Pi's 3.3V GPIO pins.

SAFETY WARNING: Never power the motor from the Raspberry Pi's 5V or 3.3V pins. Always use a separate battery pack or BEC (Battery Eliminator Circuit) for the motor's VM (Motor Voltage) terminal. Ensure the ground (GND) of the motor power supply is tied directly to the Raspberry Pi's GND to establish a common logic reference.
TB6612FNG Terminal Connects To Function & Notes
VCC RPi Pin 1 (3.3V) Logic power. Do not connect to 5V; 3.3V is optimal for Pi 4/5.
GND RPi Pin 6 (GND) & Power Supply GND Common ground. Critical for preventing logic float and brownouts.
VM External 12V Battery (+) Motor power input. Accepts 4.5V to 15V for the TB6612FNG.
PWMA RPi GPIO 12 (PWM0) Hardware PWM for Motor A speed control (0-100% duty cycle).
AIN1 RPi GPIO 5 Direction control bit 1. Set HIGH for forward.
AIN2 RPi GPIO 6 Direction control bit 2. Set LOW for forward. (HIGH/LOW = Forward; LOW/HIGH = Reverse; LOW/LOW = Coast; HIGH/HIGH = Brake).
STBY RPi 3.3V or GPIO Standby pin. Must be pulled HIGH to enable the chip. Tie to 3.3V if you don't need software sleep.
AO1 / AO2 Motor A Terminals Motor outputs. Polarity determines spin direction.

For the software side, use the gpiozero library in Python. The Motor class in gpiozero abstracts the AIN1/AIN2 direction pins and the PWM speed pin, allowing you to simply call motor.forward(0.75) to run the motor at 75% duty cycle.

Failure Signatures: Diagnosing Stalls, Hums, and Thermal Shutdowns

When integrating motors with embedded Linux systems, hardware and software bugs often manifest as distinct physical symptoms. Here is how to diagnose the three most common failure modes on the bench.

1. The Audible 'Hum' or Whine

Symptom: The motor emits a high-pitched whine but doesn't spin, or it spins with an audible buzzing sound.
Cause: This is almost always a PWM frequency issue. If your Raspberry Pi is outputting a software-timed PWM signal at 500Hz to 1kHz, the motor coils will vibrate at that acoustic frequency. Alternatively, the motor is stuck in static friction (stalled) and the driver is rapidly pulsing current without achieving breakaway.
Fix: Switch to hardware PWM on the Raspberry Pi and set the frequency to 20,000 Hz (20 kHz), which pushes the switching noise above human hearing. If the motor still hums and refuses to turn, your duty cycle is too low to overcome static friction; implement a 'kickstart' routine in code that applies 100% duty cycle for 50ms before dropping to your target speed.

2. Overheat and Thermal Shutdown

Symptom: The motor runs fine for two minutes, then stops. The TB6612FNG chip is too hot to touch. After a minute of cooling, it works again.
Cause: The TB6612FNG has internal thermal shutdown circuitry that triggers when the silicon junction hits ~150°C. This happens when you run a high-inertia load at low PWM duty cycles for extended periods, causing the RMS current to exceed the 1.2A continuous rating without the motor spinning fast enough to generate back-EMF.
Fix: Measure the current draw with a multimeter in series with the VM line. If it reads >1.2A continuously, you must either upgrade to a higher-capacity driver (like the Pololu MC33926 which handles 3A continuous) or add a heatsink and forced air cooling to the TB6612FNG.

3. The System Stall and Pi Brownout

Symptom: The motor hits a physical obstacle, stalls, and the Raspberry Pi instantly reboots or throws a low-voltage warning icon on the display.
Cause: When a DC motor stalls, it acts as a dead short, pulling maximum stall current (often 3A to 5A for small gearmotors). If your motor power supply and Raspberry Pi share the same voltage rail (e.g., both running off a single 5V USB battery bank), this massive current spike causes the voltage to sag below the Pi's 4.63V brownout threshold.
Fix: Never share power rails without massive capacitance. Use a completely separate LiPo battery for the motors, or use a high-quality buck converter (BEC) rated for at least 5A to feed the Pi from the main battery. Additionally, implement software stall detection: if you have wheel encoders, write a watchdog script that cuts PWM to 0% if the encoder reports 0 RPM while the PWM duty cycle is >20%.