Simple Pi Robot – Build a 2‑WD Autonomous Rover with Raspberry Pi
Simple Pi Robot is a hands‑on guide that turns a Raspberry Pi into a fully‑functional autonomous mobile platform. Whether you’re a hobbyist or an educator, this tutorial walks you through every step—from selecting components to writing control code and streaming video in real time.
Parts List
- Raspberry Pi (any model, Pi B+ or Pi Zero recommended)
- 40‑pin GPIO ribbon cable (for Pi B+ or Pi 2)
- Standard breadboard
- 2‑wheel chassis (e.g., Ellipzo 2‑WD kit)
- Ultrasonic distance sensor (HC‑SR04)
- Power bank for the Pi
- Rechargeable AA batteries (2100 mAh or higher)
- Male & female jumper wires, resistors
- Wi‑Fi adapter (EDUP or EDIMAX)
- 4 GB+ microSD card for the OS
- L298 dual‑motor driver board
- Servo motor (e.g., Futaba S3003)
- Miscellaneous: cable ties, foam tape for mounting
Step 1 – Choosing a Motor Driver
The L298 is a proven, cost‑effective choice that provides a regulated 5 V supply for both motors and servos. It also supports separate enable pins for speed control. Other options include the RTK Motor Controller Shield, Pololu DRV8835, or Adafruit DC/Stepper Motor HAT, but the L298’s simplicity makes it ideal for beginners.
Step 2 – Wiring the L298
Connect the board to the chassis as follows:
- DC Motor A:
OUT‑A+→OUT‑A‑ - DC Motor B:
OUT‑B+→OUT‑B‑ - Servo:
+5V(regulated) →Servo +,GND→Servo – - Enable pin: keep the jumper in place for full speed; remove it for PWM speed control.
- Connect four jumper wires from the control inputs to the Pi’s GPIO pins (see pin‑out diagram).
- Attach a single jumper wire from the servo control line to another GPIO pin.
Step 3 – Setting Up the Servo
The servo requires a constant 5 V supply and a PWM control signal. In this build we use a Futaba S3003 (4.8‑6 V). Use the RPIO.PWM library for reliable servo control via DMA:
sudo apt-get install python-setuptools
sudo easy_install -U RPIO
More on RPIO.PWM.
Step 4 – Assembling the Chassis
We use the Ellipzo 2‑WD chassis kit, which includes motors, a pan/tilt servo mount, and all necessary hardware. Follow the kit’s instructions to attach the Pi, L298, and power components.
Step 5 – Adding the HC‑SR04 Distance Sensor
Connect VCC to +5 V and GND to ground. The TRIG and ECHO pins go to GPIO pins (e.g., 18 and 17). Add a 1 kΩ resistor on the echo line to protect the Pi. The following Python snippet measures distance:
TRIG = 18
ECHO = 17
# (initialize GPIO and perform measurement)
Step 6 – Camera and Live Streaming
Attach the official Pi Camera module. Install VLC for streaming:
sudo apt-get install vlc
Stream via RTSP:
raspivid -o - -t 0 -n | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
Open the stream on any device with VLC: rtsp://<PI‑IP>:8554/.
Step 7 – Pin‑Out & Python Control Code
The full Python script below controls the robot’s motion, distance sensing, and servo. It uses RPi.GPIO for motor logic and RPIO.PWM for servo PWM.
from RPIO import PWM
import RPi.GPIO as GPIO
import time
from subprocess import call
GPIO.setmode(GPIO.BCM)
# Setup GPIO pins
GPIO.setup(19, GPIO.OUT)
GPIO.setup(26, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(20, GPIO.OUT)
GPIO.setup(21, GPIO.IN)
GPIO.setup(8, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)
GPIO.setup(9, GPIO.OUT)
TRIG = 18
ECHO = 17
# Movement functions
def fwd():
GPIO.output(19, True)
GPIO.output(26, False)
GPIO.output(16, True)
GPIO.output(20, False)
# (other movement and sensor functions omitted for brevity)
while True:
inp = raw_input()
if inp == "1":
fwd()
print("robot moving forward")
# ... (handle other commands)
GPIO.cleanup()
Step 8 – Assembly Photos
Refer to the accompanying images for visual guidance on wiring, mounting, and final assembly.
For full source code and additional resources, visit the original Simple Pi Robot page.
Manufacturing process
- Professional Fanuc Servo Motor Repair Services
- Servo‑Driven Obstacle‑Avoiding Robot: Build with Arduino & HC‑SR04
- Joy Robot: An Arduino‑ESP8266 Powered Smart Robot
- Create an Autonomous Line-Following Robot with Arduino UNO
- Build an Autonomous Home Assistant Robot: Full Parts List & Setup Guide
- Omni-Directional Robot Designed for Safe People Tracking
- Interactive Servo Motor Project with Arduino and HC‑SR04 Sensors
- Arduino‑Powered Robot Arm with Custom Controller – Servo & Potentiometer Build
- Servo Motors Explained: How They Work and Why They Matter
- Understanding Servo Motor Reducers: Functions, Benefits, and Applications