Skip to main content

Raspberry Pi Robotic Arm Control System with Camera Module and Motor Driver – Smart Automation & Vision-Based Robotics Project

Raspberry Pi Robotic Arm Control System with Camera | MakeMindz
Raspberry Pi 4 OpenCV Python PWM Servo Computer Vision

Raspberry Pi Robotic Arm Control System with Camera

📅 February 2026 ⏱ ~45 min build 🎓 Intermediate level 🔧 Hands-on project

Build a vision-guided robotic arm using Raspberry Pi 4, servo motors, and a camera module. Integrates Python control logic, PWM servo positioning, and OpenCV object detection for full pick-and-place automation.

6Servo Axes
4GPIO Pins
5VLogic Power
OpenCVVision Stack

🤖 Project Overview

This embedded robotics project combines multi-axis servo motor control, camera-based vision processing, and intelligent automation on a Raspberry Pi 4. It's designed for engineering students, AI developers, and robotics enthusiasts building real-world pick-and-place or vision-guided manipulation systems.

🧩 Components Required

🖥️
Raspberry Pi 4 Model B
Main controller — 4 GB RAM recommended
🦾
Multi-axis Robotic Arm Kit
With gripper — 4–6 DOF servo-driven
📷
Raspberry Pi Camera Module
v2 or v3 — 1080p real-time capture
⚙️
PCA9685 Servo Driver Board
I2C — 16-channel PWM control
🔋
DC Power Supply (5–6V / 3A)
Regulated external supply for motors
🔌
Power Distribution Module
Stable voltage split for logic + motors
🪛
Jumper Wires + Breadboard
GPIO to servo driver connections
💾
MicroSD Card (32 GB+)
Raspberry Pi OS with Python 3 pre-installed

🔌 Circuit Diagram

raspberry_pi_arm_circuit.svg Interactive
Raspberry Pi 4 Model B 3 4 14 15 SDA SCL CSI Port CPU (ARM) 4 GB LPDDR4 GPIO 40-pin PCA9685 16-ch PWM Driver SDA SCL CH 0–5 → Servo PWM 50 Hz / 12-bit res Addr: 0x40 (I2C) Servo CH0 Base Rotation Servo CH1 Shoulder Servo CH2 Elbow Servo CH3 Wrist / Gripper Pi Camera v2 1080p · CSI-2 Ribbon OpenCV Processing Power Supply 5V / 3A → Logic 6V / 3A → Servos Power Distribution Module I2C PWM CSI 5V LEGEND I2C Bus (SDA/SCL) GPIO Control Signal PWM / Power Camera CSI Ribbon

📌 GPIO Pin Connections

Raspberry Pi Pin Signal Connects To Purpose
GPIO 3 CTRL1 PCA9685 / Motor Driver IN1 Control signal 1
GPIO 4 CTRL2 PCA9685 / Motor Driver IN2 Control signal 2
GPIO 14 CTRL3 PCA9685 / Motor Driver IN3 Control signal 3
GPIO 15 CTRL4 PCA9685 / Motor Driver IN4 Control signal 4
GPIO 2 (SDA) I2C SDA PCA9685 SDA I2C data line
GPIO 3 (SCL) I2C SCL PCA9685 SCL I2C clock line
CSI Port MIPI CSI-2 Pi Camera Module Camera ribbon cable
5V / GND POWER Power Distribution Separate motor supply

📋 Step-by-Step Build Instructions

  1. 1
    Set Up Raspberry Pi OS
    Flash Raspberry Pi OS (64-bit, Bookworm) to your microSD using Raspberry Pi Imager. Enable SSH, I2C, and Camera Interface via sudo raspi-config → Interface Options. Update packages: sudo apt update && sudo apt upgrade -y
    ⚡ Enable I2C before connecting PCA9685 or the driver won't be detected
  2. 2
    Install Required Python Libraries
    Run the following on your Pi terminal to install all dependencies for servo control and computer vision:

    pip3 install adafruit-circuitpython-pca9685 adafruit-circuitpython-servokit opencv-python RPi.GPIO
    📦 Use a virtual environment: python3 -m venv robarm && source robarm/bin/activate
  3. 3
    Wire PCA9685 to Raspberry Pi
    Connect the PCA9685 servo driver board to the Pi's I2C pins: SDA → GPIO 2 (Pin 3), SCL → GPIO 3 (Pin 5), VCC → 3.3V, GND → GND. Connect external 6V / 3A supply to the PCA9685's V+ and GND power terminals for servo motor power.
    ⚠️ Never power servos from the Pi's 5V rail — draw will crash it
  4. 4
    Attach Servo Motors to PCA9685
    Plug servo signal wires into PCA9685 channels: CH0 = Base, CH1 = Shoulder, CH2 = Elbow, CH3 = Wrist, CH4 = Gripper. Verify I2C detection with: sudo i2cdetect -y 1 — you should see address 0x40.
  5. 5
    Connect Camera Module via CSI Port
    Gently lift the CSI connector latch on the Pi, insert the camera ribbon cable (contacts facing the HDMI ports), press latch down. Test with: libcamera-hello --timeout 5000 — a preview window should appear.
  6. 6
    Upload and Run the Control Code
    Save the Arduino sketch (for prototyping the GPIO logic) or run the Python servo control script on the Pi. The control sequence cycles through GPIO pins 3, 4, 14, and 15 with 1-second delays — confirming motor driver communication before enabling full servo PWM.
  7. 7
    Integrate OpenCV for Vision-Guided Automation
    Open a Python script and use cv2.VideoCapture(0) to grab camera frames. Apply color masking or YOLO object detection to identify target objects. Map detected centroid coordinates to servo angles using inverse kinematics or a lookup table, then send angles to PCA9685 channels via ServoKit.
    🧠 Start with HSV color detection before moving to YOLO for easier debugging
  8. 8
    Calibrate and Test Pick-and-Place
    Define home position angles for all joints. Write a pick sequence: move to object → lower arm → close gripper → lift → move to drop zone → open gripper. Test each axis independently before running the full automation loop. Fine-tune servo angle limits to prevent mechanical over-extension.
    ✅ Set min/max angle limits in ServoKit to protect servo gears

💻 Arduino Control Sketch

Note: This sketch demonstrates the GPIO signal sequencing logic. In the full Raspberry Pi build, this logic runs as a Python script using RPi.GPIO or the ServoKit library instead.
Arduino C++
/*
 * Raspberry Pi Robotic Arm Control System
 * MakeMindz.com — Robotics Project Tutorial
 *
 * Controls a robotic arm via GPIO signal sequencing.
 * Raspberry Pi handles camera vision; this sketch
 * demonstrates motor driver signal logic.
 *
 * Connections:
 *   GPIO 3  → Control signal 1 (Base motor)
 *   GPIO 4  → Control signal 2 (Shoulder motor)
 *   GPIO 14 → Control signal 3 (Elbow motor)
 *   GPIO 15 → Control signal 4 (Wrist/Gripper)
 *   Camera  → CSI Port (handled by Raspberry Pi)
 */

#define CONTROL_PIN1  3
#define CONTROL_PIN2  4
#define CONTROL_PIN3  14
#define CONTROL_PIN4  15

void setup() {
  // Initialize GPIO pins as digital outputs
  pinMode(CONTROL_PIN1, OUTPUT);
  pinMode(CONTROL_PIN2, OUTPUT);
  pinMode(CONTROL_PIN3, OUTPUT);
  pinMode(CONTROL_PIN4, OUTPUT);

  // Camera module initialized on Raspberry Pi side
  // via libcamera / OpenCV — no setup required here
}

void loop() {
  // Sequential control signals to robotic arm joints

  // --- Base Rotation ---
  digitalWrite(CONTROL_PIN1, HIGH);
  delay(1000);
  digitalWrite(CONTROL_PIN1, LOW);
  delay(1000);

  // --- Shoulder Joint ---
  digitalWrite(CONTROL_PIN2, HIGH);
  delay(1000);
  digitalWrite(CONTROL_PIN2, LOW);
  delay(1000);

  // --- Elbow Joint ---
  digitalWrite(CONTROL_PIN3, HIGH);
  delay(1000);
  digitalWrite(CONTROL_PIN3, LOW);
  delay(1000);

  // --- Wrist / Gripper ---
  digitalWrite(CONTROL_PIN4, HIGH);
  delay(1000);
  digitalWrite(CONTROL_PIN4, LOW);
  delay(1000);

  // Sequence repeats — replace with vision-triggered
  // logic from Raspberry Pi serial commands
}

🐍 Python Servo Control (Raspberry Pi)

Python 3
# Raspberry Pi Robotic Arm — Python Control Script
# MakeMindz.com | Requires: adafruit-circuitpython-servokit

import time
from adafruit_servokit import ServoKit
import board, busio

# Initialize PCA9685 via I2C (address 0x40)
kit = ServoKit(channels=16)

# Servo channel map
BASE     = 0
SHOULDER = 1
ELBOW    = 2
WRIST    = 3
GRIPPER  = 4

def move_to(channel, angle, delay=0.5):
    """Move servo to angle (0–180°) with optional delay."""
    kit.servo[channel].angle = max(0, min(180, angle))
    time.sleep(delay)

def home_position():
    """Return all joints to neutral position."""
    for ch in [BASE, SHOULDER, ELBOW, WRIST, GRIPPER]:
        move_to(ch, 90)

def pick_and_place():
    """Simple pick-and-place sequence."""
    home_position()

    # Move to target object
    move_to(BASE, 45)
    move_to(SHOULDER, 60)
    move_to(ELBOW, 120)

    # Open gripper, lower, grip, lift
    move_to(GRIPPER, 0)     # open
    move_to(SHOULDER, 80)    # lower
    move_to(GRIPPER, 60)     # grip
    move_to(SHOULDER, 40)    # lift

    # Move to drop zone
    move_to(BASE, 135)
    move_to(SHOULDER, 80)
    move_to(GRIPPER, 0)     # release

    home_position()

# Run sequence
while True:
    pick_and_place()
    time.sleep(2)

🎮 Try the Simulation

🔬

Wokwi Simulator — Raspberry Pi + Servo

Paste the diagram.json above into Wokwi to simulate servo PWM control, I2C bus, and GPIO sequencing without hardware.

Cirkit Designer — Full Circuit Simulation

Import the circuit and run a complete simulation with PCA9685 servo driver, camera module placeholder, and power supply layout.

Key Features

🔁
Multi-Axis Control
Up to 6 servo axes via PCA9685 I2C driver with 12-bit resolution PWM
📷
Camera Vision
Real-time object detection with OpenCV color masking or YOLO neural network
PWM Precision
50 Hz servo control, hardware-level accuracy independent of CPU load
🔋
Split Power
Separate supplies for logic (5V) and motors (6V) eliminate voltage noise
🤖
AI Ready
Expandable with TensorFlow Lite, YOLO, or ROS2 for advanced manipulation
🌐
IoT Enabled
Add MQTT or WebSocket interface for remote arm control via dashboard

🔗 Related Projects on MakeMindz

© 2026 MakeMindz.com · Robotics, IoT & Embedded Systems Tutorials

Comments

try for free