Build a DIY Robot Dog with Raspberry Pi | Servo Motor Quadruped

Build a DIY Robot Dog with Raspberry Pi | Servo Motor Quadruped | MakeMindz
🍓 Raspberry Pi · 8× Servo Motors

Build Your Own
Robot Dog
That Really Walks!

A four-legged mini robot powered by Raspberry Pi — it trots, sits, wags, and obeys your Python commands! 🐾⚡

⏱️ 5–6 Hours 🔧 Advanced Build 🎓 Age 13+ 💰 ~₹3,800 🐍 Python Code
Pi 🍓 Shoulder servo Knee servo
8 Servo Motors
4 Walking Legs
2 Joints per Leg
Pi Brain Power

🐾 How Does a Robot Dog Walk?

Walking on four legs is actually a fascinating engineering problem! Each leg has two servo motors — one at the shoulder (moves leg forward/back) and one at the knee (bends the leg up/down). By coordinating all four legs in the right sequence, the robot trots forward smoothly.

🦵 2 DOF per Leg

DOF = Degree of Freedom. Each leg has 2 joints (shoulder + knee) controlled by one servo each.

🔀 Trot Gait

Front-Left & Rear-Right move together, then Front-Right & Rear-Left — just like a real dog trotting!

⚙️ PCA9685 Driver

Controls all 8 servos via I²C — Raspberry Pi sends commands to one chip, chip drives all servos.

🐍 Python Control

Python on the Pi calculates leg angles and sends precise timing signals to each servo in sequence.

🌍 Real-World Link: Boston Dynamics' Spot robot dog uses the exact same walking principles — just with much more powerful motors and advanced balance sensors. Your mini dog is the same idea at pocket size!

🛒 Parts Shopping List

All available on Amazon India, Robu.in, or RoboElements. Budget: approximately ₹3,800:

🍓
Raspberry Pi 4 (2GB) The brain — runs Python, sends servo commands over I²C.
🎛️
PCA9685 16-Channel Servo Driver Controls all 8 servos from a single I²C connection to the Pi.
⚙️
8× MG90S Metal Gear Servo 2 per leg × 4 legs = 8 servos. Metal gears handle the load.
🏗️
Robot Dog Frame / Chassis Kit Laser-cut acrylic or 3D-printed frame holding the leg structure.
🔋
2× 18650 LiPo Battery + Holder 7.4V LiPo for servos; must be separate from Pi power.
5V 3A USB-C Power Bank (Pi) Powers the Raspberry Pi 4 separately from servo power.
📉
LM2596 Buck Converter (7.4V → 6V) Steps down LiPo voltage to safe 6V for servo motors.
📺
Small OLED 0.96" Display (I²C) Shows current gait mode and battery level on the dog's back.
🔌
Jumper Wires + Screwdriver + M3 Screws For wiring and assembling the chassis frame.
🃏
32GB MicroSD Card (Class 10) Stores Raspberry Pi OS and your Python robot code.

Circuit Diagram

Key rule: Raspberry Pi and servos use completely separate power supplies. Servos draw too much current — sharing power would crash the Pi!

Mini Robot Dog — Complete Wiring Diagram Raspberry Pi 4 🍓 Brain 3.3V (Pin 1) 5V (Pin 4) GND (Pin 6) GPIO 2 / SDA GPIO 3 / SCL USB-C Power 5V (from bank) PCA9685 16-Ch Servo Driver VCC (3.3V) GND SDA SCL V+ (6V servo pwr) CH0 FL-Shoulder CH1 FL-Knee CH2 FR-Shoulder CH3 FR-Knee CH4 RL-Shoulder CH5 RL-Knee CH6 RR-Shoulder CH7 RR-Knee SDA SCL FL Shoulder MG90S · CH0 FL Knee MG90S · CH1 FR Shoulder MG90S · CH2 FR Knee MG90S · CH3 RL Shoulder MG90S · CH4 RL Knee MG90S · CH5 RR Shoulder MG90S · CH6 RR Shoulder MG90S · CH6 RR Knee MG90S · CH7 🔋 7.4V LiPo 2× 18650 Cells LM2596 Buck 7.4V → 6V for servos 6V Servo Power USB-C Power Bank 5V 3A → Pi 4 only Gait: TROT Battery: 85% OLED 0.96" I²C LEGEND: I²C Servo CH Power All GNDs share common ground
📌 COMPLETE PIN REFERENCE — RASPBERRY PI 4 GPIO PCA9685 Servo Driver ─────────────────────────────────── VCC ──► 3.3V (Pin 1) GND ──► GND (Pin 6) SDA ──► GPIO 2 / SDA1 (Pin 3) SCL ──► GPIO 3 / SCL1 (Pin 5) V+ ──► 6V from LM2596 buck converter // servo power 8× MG90S Servos → PCA9685 Channels ────────────────── Front-Left Shoulder ──► CH0 Front-Left Knee ──► CH1 Front-Right Shoulder ──► CH2 Front-Right Knee ──► CH3 Rear-Left Shoulder ──► CH4 Rear-Left Knee ──► CH5 Rear-Right Shoulder ──► CH6 Rear-Right Knee ──► CH7 OLED 0.96" (I²C — shared bus) ──────────────────────────── SDA ──► GPIO 2 (same I²C bus as PCA9685) SCL ──► GPIO 3 // address: 0x3C Power ──────────────────────────── Raspberry Pi ──► 5V 3A USB-C power bank Servo power ──► 7.4V LiPo → LM2596 → 6V out → PCA9685 V+

🔧 Step-by-Step Build Guide

Work through every step in order. Assemble the frame first, then wire, then code.

1
🍓 Set Up Raspberry Pi OS

Flash Raspberry Pi OS Lite (64-bit) on your 32GB SD card using the Raspberry Pi Imager tool. Boot it up, connect to Wi-Fi, then open a terminal and install the required Python libraries:

TERMINAL
sudo apt-get update && sudo apt-get upgrade -y
# Enable I2C interface
sudo raspi-config
# → Interface Options → I2C → Enable → Reboot

# Install Python libraries
pip3 install adafruit-circuitpython-pca9685 \
             adafruit-circuitpython-motor  \
             board busio luma.oled pillow

# Verify I2C devices found (should see 0x40 PCA9685 + 0x3C OLED)
sudo i2cdetect -y 1
✅ Check: After i2cdetect you should see addresses 0x40 (PCA9685) and 0x3C (OLED) in the grid. If they're missing, recheck your SDA/SCL wiring!
2
🏗️ Assemble the Dog Chassis

Assemble the frame following these mounting positions:

  • Body plate: The main platform. Mount the Raspberry Pi and PCA9685 on top
  • Shoulder servos: 4 servos mount at the corners of the body plate, pointing down. Their horns attach to the upper leg segments
  • Knee servos: 4 servos mount mid-leg, connecting the upper and lower leg segments
  • Leg length: Upper leg ~5 cm, lower leg ~6 cm for best walking geometry
  • Feet: Small rubber caps or 3D-printed paw pads for grip
⚙️ Servo centering first: Before bolting legs to servos, run the calibration script (Step 3) to center all servos at 90°. Then attach the legs pointing straight down. This prevents misaligned starting positions!
3
🎯 Calibrate All Servos

Run this script before assembling legs — it centers every servo at 90° so you can attach legs in the correct neutral position:

calibrate_servos.py
import board, busio
from adafruit_pca9685 import PCA9685
from adafruit_motor import servo
import time

i2c = busio.I2C(board.SCL, board.SDA)
pca = PCA9685(i2c)
pca.frequency = 50

# Create servo objects for all 8 channels
servos = [
    servo.Servo(pca.channels[i], min_pulse=500, max_pulse=2500)
    for i in range(8)
]

print("Setting all 8 servos to 90° (neutral position)...")
for s in servos:
    s.angle = 90
    time.sleep(0.05)

print("All servos centered! Attach legs pointing straight down.")
print("Press Ctrl+C when done.")
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    pca.deinit()
    print("Done! Now bolt the legs in place.")
4
🐾 Upload the Walking Robot Code

This is the complete Python brain — it controls the trot gait, sit, stand, and wag-tail behaviours:

robot_dog.py
import board, busio, time
from adafruit_pca9685 import PCA9685
from adafruit_motor import servo

# ── Hardware init ────────────────────────────────
i2c = busio.I2C(board.SCL, board.SDA)
pca = PCA9685(i2c)
pca.frequency = 50

# 8 servos: channels 0-7
# Even channels = shoulder, Odd = knee
# 0,1=FL  2,3=FR  4,5=RL  6,7=RR
servos = [
    servo.Servo(pca.channels[i], min_pulse=500, max_pulse=2500)
    for i in range(8)
]

# ── Angle helper ─────────────────────────────────
# ch: 0-7, angle: 0-180
def set_servo(ch, angle):
    angle = max(0, min(180, angle))
    servos[ch].angle = angle

# Move all 8 servos at once from current position dict
def pose(angles, duration=0.3):
    # angles = [FL_sh, FL_kn, FR_sh, FR_kn,
    #           RL_sh, RL_kn, RR_sh, RR_kn]
    for i, ang in enumerate(angles):
        set_servo(i, ang)
    time.sleep(duration)

# ── Preset poses ─────────────────────────────────
NEUTRAL = [90,90, 90,90, 90,90, 90,90]
SIT     = [90,90, 90,90, 60,130, 60,130]  # rear legs bent
STAND   = [90,70, 90,70, 90,70, 90,70]   # all knees straight

# ── Trot gait (diagonal pairs) ───────────────────
# Pair A: FL + RR step forward while FR + RL support
# Pair B: FR + RL step forward while FL + RR support

STEP_FWD = 25   # how many degrees shoulders swing
LIFT     = 30   # how much knee lifts leg off ground

def trot_step_A():
    # Pair A (FL+RR) lifts and steps forward
    # Pair B (FR+RL) stays grounded and pushes back
    pose([
        90-STEP_FWD, 90-LIFT,    # FL: swing fwd + lift
        90+STEP_FWD, 90,          # FR: push back, grounded
        90+STEP_FWD, 90,          # RL: push back, grounded
        90-STEP_FWD, 90-LIFT      # RR: swing fwd + lift
    ], 0.18)
    pose([                           # lower pair A feet
        90-STEP_FWD, 90,
        90+STEP_FWD, 90,
        90+STEP_FWD, 90,
        90-STEP_FWD, 90
    ], 0.1)

def trot_step_B():
    # Pair B (FR+RL) lifts and steps forward
    pose([
        90-STEP_FWD, 90,            # FL: push back
        90+STEP_FWD, 90-LIFT,      # FR: swing fwd + lift
        90-STEP_FWD, 90-LIFT,      # RL: swing fwd + lift
        90+STEP_FWD, 90            # RR: push back
    ], 0.18)
    pose([                           # lower pair B feet
        90-STEP_FWD, 90,
        90+STEP_FWD, 90,
        90-STEP_FWD, 90,
        90+STEP_FWD, 90
    ], 0.1)

def walk_forward(steps=4):
    pose(STAND, 0.3)
    for _ in range(steps):
        trot_step_A()
        trot_step_B()
    pose(NEUTRAL, 0.3)

def sit_down():
    pose(SIT, 0.5)
    print("🐾 Sitting!")

def wag_tail(wags=4):
    # Simulate tail wag by wiggling rear-right shoulder
    for _ in range(wags):
        set_servo(6, 70);  time.sleep(0.15)
        set_servo(6, 110); time.sleep(0.15)
    set_servo(6, 90)
    print("🐾 Tail wagging!")

# ── Main behaviour sequence ───────────────────────
if __name__ == "__main__":
    print("🤖 Robot Dog Starting!")
    pose(NEUTRAL, 1.0)    # start in neutral

    try:
        while True:
            print("▶ Walking forward...")
            walk_forward(steps=6)
            time.sleep(0.5)

            print("▶ Sitting...")
            sit_down()
            time.sleep(1.0)

            print("▶ Wagging tail...")
            wag_tail(5)
            time.sleep(0.5)

            pose(NEUTRAL, 0.5)
            time.sleep(1.0)

    except KeyboardInterrupt:
        pose(NEUTRAL, 0.5)
        pca.deinit()
        print("🐾 Robot Dog stopped. Goodbye!")
🚀 Run it! Save as robot_dog.py and run with python3 robot_dog.py. Your dog will walk, sit, and wag in a loop! Press Ctrl+C to stop gracefully and return to neutral.
🎯 Tuning tip: If legs look stiff or hit the ground awkwardly, adjust STEP_FWD (try 20–35) and LIFT (try 20–40) to find the smoothest walk for your chassis dimensions!
5
📺 Add the OLED Status Display

Add this code to show the current behaviour on the OLED screen mounted on the dog's back — so you can see what it's doing from a distance:

oled_status.py
from luma.core.interface.serial import i2c
from luma.oled.device import ssd1306
from luma.core.render import canvas
from PIL import ImageFont

serial = i2c(port=1, address=0x3C)
oled   = ssd1306(serial, width=128, height=64)

def show_status(mode, step=0):
    with canvas(oled) as draw:
        draw.text((2, 4),  "🐾 Robot Dog", fill="white")
        draw.text((2, 22), f"Mode: {mode}",  fill="white")
        draw.text((2, 40), f"Step: {step}",  fill="white")

# Call show_status("TROT", step) inside walk_forward()
# Call show_status("SIT")  inside sit_down()
# Call show_status("WAG")  inside wag_tail()

🛠️ Troubleshooting Guide

Quadruped robots are complex — here are the most common problems and how to fix them:

🔴 Problem🟡 Likely Cause✅ Fix
PCA9685 not found on I²C I²C not enabled or wiring wrong Run raspi-config → Interface Options → enable I²C. Recheck SDA→GPIO2 and SCL→GPIO3
Servos jitter constantly Power supply under-voltage Confirm LiPo → buck converter outputs exactly 6V. Cheap 18650 cells may sag under load
Dog falls over while walking Leg geometry / servo angles wrong Reduce STEP_FWD to 15° first. Ensure centre of gravity is between the four feet
One leg moves differently That servo was attached at wrong angle Re-run calibrate_servos.py, detach that leg's horn, and reattach pointing straight down at 90°
Pi reboots during movement Servos drawing current through Pi's 5V rail Servo V+ must come from the buck converter, NOT the Pi's GPIO 5V pin. Check V+ wiring on PCA9685
Walk looks jerky not smooth Pose duration too short Increase duration in pose() calls from 0.18 to 0.25 seconds for smoother transitions
OLED shows nothing I²C address mismatch Run sudo i2cdetect -y 1 — if OLED shows as 0x3D, change address in the code

🚀 Level Up Your Robot Dog!

Once your dog walks, these upgrades turn it into a truly impressive robot:

📷 Eyes Camera

Add a Pi Camera to the head — stream video from the dog's point of view to your phone!

🎤 Voice Commands

Add a USB microphone — say "sit", "walk", "wag" and the dog obeys using speech_recognition!

📡 Remote Control

Control your dog from a phone web browser using a Flask web server running on the Pi!

🔊 Dog Sounds

Add a small USB speaker — play bark.mp3 and growl.mp3 sounds at the right moments!

👁️ Obstacle Avoidance

Add an HC-SR04 ultrasonic sensor on the nose — the dog stops and turns before hitting walls!

🎮 Gamepad Control

Connect a Bluetooth PS4/Xbox controller to the Pi for manual real-time gait control!


❓ Frequently Asked Questions

Why use Raspberry Pi instead of Arduino for this project?

Arduino is great for simple servo control, but for a walking gait you need precise timing across 8 servos simultaneously. Raspberry Pi runs Python with proper threading support, can add a camera, run Wi-Fi, host a web server, and do speech recognition — all things Arduino can't do on its own.

Why do the servos need their own separate power supply?

Eight MG90S metal-gear servos under load can draw 2–4 Amperes combined. The Raspberry Pi's power supply is rated for ~3A just for itself. Mixing them would cause the Pi to brownout and reboot during movement. Always use a dedicated battery for servos!

Can I 3D print the chassis instead of buying a kit?

Absolutely! Search "Mini Quadruped Robot Dog STL" on Thingiverse or Printables — there are free designs sized for MG90S servos. Print in PLA at 40% infill for a good strength-to-weight ratio. Printing takes about 6–8 hours for a full chassis.

How do I make it turn left and right?

Great next challenge! For turning right, make the left-side legs take larger steps forward than the right-side legs. For sharp turns, swing one side forward while the other side walks backward — called a "spin turn." Adjust the STEP_FWD value per side in the trot functions.

Is this a good project for a science exhibition?

One of the best possible choices! A walking quadruped robot immediately impresses any audience. Be ready to explain the trot gait pattern, inverse kinematics (angle calculations for leg positions), and why diagonal pairs move together. The real Boston Dynamics story about Spot is a great hook to open with!

The dog walks but keeps drifting to one side — why?

This happens when servos from different batches have slightly different mechanical zero positions. Fix by adding small individual offset values per servo in the code — for example, if CH2 drives slightly left, change its neutral from 90 to 93. Tune each servo's offset until the dog walks straight.

Building the next generation of robotics engineers, one paw at a time.

#RobotDog #RaspberryPiRobot #QuadrupedRobot #ServoMotorProject #KidsRobotics #STEMProject #MakeMindz #WalkingRobot #PCA9685 #RoboticsForKids

Comments

Product Cards
Buddy Bot eBook
⭐ New 2026 Release
Build Your
Own Robot!
3D design, wiring &
Arduino coding.
Young inventors love it!
🖨️
3D Print
All parts
Wire it
Circuit guide
💻
Code it
Arduino IDE
🤖
Watch it
Walk & react
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Website Offer
₹499 300
🌍 International: $5 USD
One-time · Instant digital delivery
🔒 Secured by Razorpay · Your data is safe
📄 Download Free Sample Copy
🔒 Secured by Razorpay · Your data is safe
🍓
Raspberry Pi Pico Mastery
21 Projects
⚡ Launch Price — 80% OFF
Learn Pico
Build 21 Projects!
MicroPython · Wokwi
IoT · Certificate
Perfect for beginners!
🖥️
Wokwi
No hardware
🐍
MicroPy
From zero
🔨
21 Projects
IoT + sensors
📄
Certificate
Verified cert
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Launch Offer
₹999 200 80% OFF
🌍 International: $5 USD
One-time · Lifetime access · No subscription
🔒 Secured by Razorpay · UPI · Cards · NetBanking
🎉

You're in!

Payment successful! Your Buddy Bot eBook is ready. Time to build!

📖 Access Your eBook Now
🎉

Enrolled!

Payment successful! Lifetime access to all 21 Pico Projects is yours!

🍓 Go to My Course