Standalone Wiring Guide – Raspberry Pi Robot Car

For Raspberry Pi 4 & 5. Safe motor wiring, power isolation, ultrasonic hookup, and mandatory level shifting. Works with L298N or TB6612FNG.

Motor Driver Wiring

Pi GPIO inputs to driver control pins:

Speed control (optional): Use PWM pins for PWMA / PWMB (TB6612FNG) or ENA / ENB (L298N) if you want speed control. Otherwise tie them high.

Motors → Driver

Left motor:

Right motor:

If a wheel spins backward, swap + and − for that motor only.

Power Wiring (Critical)

Motors + driver must be powered from a separate battery pack:

Raspberry Pi is never powered from the motor battery. The Pi must use its own USB-C PSU.

Ground rule: Pi GND + Driver GND + Battery − + Sensor GND must be tied together.

Ultrasonic Sensor (HC-SR04)

Voltage Divider (required)

Use 2 kΩ + 1 kΩ to drop ECHO from 5V → 3.3V:

HC-SR04 ECHO → 2 kΩ → GPIO25
                 |
                1 kΩ
                 |
                GND
    

Never feed 5V directly into Pi GPIO pins.

Pin Map

Component Signal Pi GPIO / Power
Motor driverIN1GPIO17
Motor driverIN2GPIO18
Motor driverIN3GPIO22
Motor driverIN4GPIO23
UltrasonicTRIGGPIO24
UltrasonicECHOGPIO25 (via divider)
UltrasonicVCC5V
UltrasonicGNDGND
Driver + motorVINMotor battery +
Driver + motorGNDShared ground

Pre-Power Checklist

⬅ Back to Tutorial 01