New here? This part covers wiring the C101 4WD kit to a Raspberry Pi 3B via L298N and writing Python directly on the Pi to drive the car — no laptop, no USB cable, no Arduino middleman.
If some of the hardware setup feels unfamiliar, a quick read through Part 12 (Raspberry Pi setup and SSH) will fill in the gaps. Otherwise, let's go.Before a Robot Can Think, It Has to Walk
In Part 12, we moved the robot's brain off the laptop and into the Pi itself. Smart. But a brain with no body isn't much use.
Every autonomous robot — from a Roomba to a Mars rover — runs on the same four-step loop:
Perception → Localization → Planning → Control
The robot senses its environment, figures out where it is, decides where to go, and moves. Repeat forever.
But here's the thing: before any of that can happen, the robot needs to know how to move in the first place. You can't plan a route if the wheels don't respond to commands. So the real learning order looks like this:
Learn to move (Control) first → then add Perception → Localization → Planning → Control
Think of a toddler. First they learn to walk — wobbly, directionless, occasionally into a wall. Nobody expects them to navigate to the kitchen and back on day one. Walking comes first. Everything else comes later.
That's exactly what we're doing today. Teaching the robot to walk.
And once it can walk — if the battery holds and nothing gets in the way — it could theoretically keep going in a straight line forever. "So what?" you might say. "Leave a Toyota running in an empty parking lot and it'll roll until it hits something." True. But can you program that Toyota to take two steps forward and one step back, on repeat, for the entire journey? Or to sway left and right while moving forward? Our robot can do both — in about five lines of Python. Try that with a regular car.
What You Need
| Component | Notes | Est. Cost |
|---|---|---|
| Laptop | For setup via VNC only | Already owned |
| Raspberry Pi 3B | Already have (Part 12) | |
| MicroSD 32/64GB | Already have (Part 12) | |
| L298N Motor Driver | Already have (Phase 1) | |
| C101 4WD Kit | ~$20 | |
| Portable USB Power Bank (5V) | Powers the Pi | Already have |
| Li-ion Battery Pack 7.4V | Powers the motors | ~$12 |
A few notes before wiring:
✅ Power Bank for Pi: Use a slim or mini power bank — small, light, easy to mount. The Pi 3B uses a Micro-USB port, so if your power bank only has USB-A output, you'll need a USB-A to Micro-USB cable.
✅ Treedix 5V UPS for Pi (alternative): Mounts directly onto the Pi which is convenient, but uses 18650 batteries that need to be physically removed for charging. More hassle than it's worth for most setups — not recommended.
✅ C101 metal chassis: The frame is metal. Never let the underside of any circuit board (where the solder joints are) touch the metal chassis directly — instant short circuit, instant damage. Insulate the bottom of every board before mounting. A strip of electrical tape, a piece of acrylic, or a chassis kit made from non-conductive material all work fine.
✅ Li-ion Battery Pack 7.4V: Get one that comes with pre-attached positive (+) and negative (−) leads. Without them, getting power out of the pack becomes a project in itself.
✅ Raspberry Pi GPIO: The Pi's pins are completely different from the Arduino Nano. The diagram below shows the BCM numbering we'll use in code — the inner numbers are the GPIO numbers, the outer labels are the physical pin names. When in doubt, cross-reference with the official Raspberry Pi pinout at raspberrypi.com.
✅ Motor wire connections: The motor terminals accept bare wire — strip the end, insert, tighten the screw. Soldering the wire tips first makes for a more reliable connection, but twisted bare wire works too.
Step 1 — Assemble the C101 Kit First
Before any wiring, assemble the wheels and motors onto the C101 chassis. Follow the official assembly guide: 🔗 https://m.media-amazon.com/images/I/B1reNOGPGgL.pdf
Once assembled, decide which end is the front of the car and mark it. This matters when testing motor directions later.
Step 2 — Wire Everything Up
Power connections:
| From | To |
|---|---|
| Battery Pack (+) | L298N 12V terminal |
| Battery Pack (−) | L298N GND terminal |
| Power Bank (5V) | Pi micro-USB port |
GPIO signal connections (Pi → L298N):
| L298N Pin | Raspberry Pi GPIO (BCM) | Function |
|---|---|---|
| ENA | GPIO 18 | Left motor speed (PWM) |
| IN1 | GPIO 27 | Left motor direction |
| IN2 | GPIO 22 | Left motor direction |
| IN3 | GPIO 23 | Right motor direction |
| IN4 | GPIO 24 | Right motor direction |
| ENB | GPIO 13 | Right motor speed (PWM) |
| GND | Pin 14 (GND) | Common ground — mandatory |
⚠️ The GND connection is not optional. Without a shared ground between the Pi and L298N, no control signal gets through — the motors won't respond to anything. Use physical pin 14 on the Pi (which is a GND pin) — not GPIO 14, which is something else entirely.
Don't connect the motors yet. Wire everything else first, then test each motor individually in Step 4.
Step 3 — The Python Code
Connect to the Pi via VNC Viewer, open Thonny Python IDE (Menu → Programming → Thonny), and paste this in:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# GPIO pin assignments
ENA = 18 # Left speed
IN1 = 27 # Left direction
IN2 = 22 # Left direction
IN3 = 23 # Right direction
IN4 = 24 # Right direction
ENB = 13 # Right speed
# Configure all pins as outputs
for pin in [ENA, ENB, IN1, IN2, IN3, IN4]:
GPIO.setup(pin, GPIO.OUT)
# Set up PWM at 50Hz
pwm_A = GPIO.PWM(ENA, 50)
pwm_B = GPIO.PWM(ENB, 50)
pwm_A.start(0)
pwm_B.start(0)
def set_motor(in1, in2, pwm, speed):
if speed >= 0:
GPIO.output(in1, GPIO.HIGH)
GPIO.output(in2, GPIO.LOW)
else:
GPIO.output(in1, GPIO.LOW)
GPIO.output(in2, GPIO.HIGH)
pwm.ChangeDutyCycle(abs(speed))
def forward(speed):
set_motor(IN1, IN2, pwm_A, speed)
set_motor(IN3, IN4, pwm_B, speed)
def backward(speed):
set_motor(IN1, IN2, pwm_A, -speed)
set_motor(IN3, IN4, pwm_B, -speed)
def turn_left(speed):
set_motor(IN1, IN2, pwm_A, -speed)
set_motor(IN3, IN4, pwm_B, speed)
def turn_right(speed):
set_motor(IN1, IN2, pwm_A, speed)
set_motor(IN3, IN4, pwm_B, -speed)
def stop_car():
set_motor(IN1, IN2, pwm_A, 0)
set_motor(IN3, IN4, pwm_B, 0)
try:
print("Moving forward for 2 seconds...")
forward(75)
time.sleep(2)
print("Turning right for 1 second...")
turn_right(75)
time.sleep(1)
print("Turning left for 1 second...")
turn_left(75)
time.sleep(1)
print("Moving backward for 2 seconds...")
backward(50)
time.sleep(2)
print("Stopping.")
stop_car()
time.sleep(1)
except KeyboardInterrupt:
print("Interrupted.")
finally:
stop_car()
pwm_A.stop()
pwm_B.stop()
GPIO.cleanup()One thing worth explaining: The C101 has four DC motors but no front steering servo — unlike the RC car we modified earlier, which had a separate servo for turning. Instead, the C101 steers by spinning one side faster than the other. Left side faster → turns right. Right side faster → turns left. This is called differential steering (or skid steering) — the same method used by tanks, bulldozers, and most 4WD robot kits. It's not elegant, but it works.
Step 4 — Test Each Motor Before Assembling
With four motors, a wiring mistake is easy to make and painful to debug. If one motor spins the wrong way, the car might spin in circles or refuse to move at all — and figuring out which motor is wrong when they're all mounted and wired is genuinely frustrating.
The fix: test each motor individually before final assembly.
Flip the car upside down. Connect one motor at a time to OUT3/OUT4, hit Run, and watch the "Moving forward" message appear. If the wheel spins counter-clockwise (viewed from outside the car, arrow pointing backward) — correct. If it spins clockwise — swap the two wires between OUT3 and OUT4.
Write down your results:
Motor 1 (front-left): Yellow → OUT1, Blue → OUT2 ✅
Motor 2 (rear-left): ...
Motor 3 (front-right): ...
Motor 4 (rear-right): ...Once all four are confirmed, connect left-side motors to OUT1/OUT2 and right-side motors to OUT3/OUT4 according to your notes.
Step 5 — Mount Everything and Run
Now comes the fun part: fitting the Pi, L298N, power bank, and battery pack onto the C101 chassis without it looking like a yard sale on wheels. Space is tight — leave room at the front for the HC-SR04 ultrasonic sensor that's coming in the next part.
A simple trick: cut an ice cream stick to about 4 inches and attach it to the front of the car as a sensor mount. Cheap, light, effective.
Set the car on an open floor. Open Thonny, press Run, and watch.
What Just Happened
This is not the same as the RC car from Phase 1. That car still needed a human pressing keyboard keys. This one runs a Python program stored on the Pi itself — no laptop attached, no USB cable, no Bluetooth link. The Pi wakes up, reads the code, and drives.
Watching it move for the first time — four wheels spinning, the car rolling forward on its own — is one of those moments that's genuinely hard to describe. It feels a bit like watching a toddler take their first steps: wobbly, uncertain, but completely self-powered. And entirely earned.
That moment is worth at least one Starbucks Caffè Latte.
What's Next
The robot can move. Now it needs to sense. In Part 14, we add the HC-SR04 ultrasonic sensor to the Pi — and the car will stop automatically when something gets in its way.
Step one of the four-step loop is done. Perception is next.
