Fareed Mohmed← Project library

Engineering · Raspberry Pi · Project 35 of 47 · Robotics · Intermediate

Pick-and-place robot arm (2 servos)

Two servos make a small arm: one turns the base and one opens and closes the gripper. Press the button and the arm runs a full pick-and-place cycle.

▶ Open in the simulator

Raspberry Pi simulator drawing of the circuit for Pick-and-place robot arm (2 servos): the board, its power supply and the parts wired to the 40-pin header

Parts in this circuit

PartType
Base servoServo
Gripper servoServo
Start cyclePush button

Wiring, pin by pin

Red = 5 V, orange = 3.3 V, black = GND, other colours = signals. “Pin” is the position on the 40-pin header; the GPIO number is what the code uses. Power the Pi from a 5.1 V supply and wire with the power off.

#ColourFrom (part and leg)To (header pin)
1ColouredBase servo - signalPin 11 (GPIO17)
2RedBase servo - 5 VPin 2 (5V)
3BlackBase servo - GNDPin 6 (GND)
4ColouredGripper servo - signalPin 12 (GPIO18)
5RedGripper servo - 5 VPin 4 (5V)
6BlackGripper servo - GNDPin 9 (GND)
7ColouredStart cycle - SignalPin 13 (GPIO27)
8BlackStart cycle - GNDPin 14 (GND)

Python code (gpiozero)

from gpiozero import AngularServo, Button
from time import sleep

base = AngularServo(17, min_angle=-90, max_angle=90)       # turns left and right
grip = AngularServo(18, min_angle=-90, max_angle=90)       # 60 = open, -20 = closed
start = Button(27)

def move(base_angle, grip_angle, text):
    print(text)
    base.angle = base_angle
    grip.angle = grip_angle
    sleep(1)

move(0, 60, "Home position, gripper open")

while True:
    start.wait_for_press()
    move(-60, 60, "1. Swing over the part")
    move(-60, -20, "2. Close the gripper: part picked")
    move(60, -20, "3. Swing to the drop point")
    move(60, 60, "4. Open the gripper: part placed")
    move(0, 60, "5. Back home. Ready")

How the code works

You will learn

  • Coordinating two servos
  • Writing a sequence as a list of poses
  • Using a function to avoid repeating code

Try this

  • Press the start button and follow the numbered steps in the console.
  • Change the drop point to -60 and the pickup to 60.
  • Add a second button that stops the arm and sends it home.

On a real Pi

  • Small SG90 servos are weak. A real gripper and arm need metal-gear servos and a separate 5 V supply with 3 A or more.
  • Move in small steps, not in one jump, to avoid shaking the load and the arm.
  • Fit a stop button that cuts the servo power. Keep fingers away from the arm.

Parts to buy

The links open a search on each store, so you see what is in stock today. Check the model, voltage and price before you order.

#ItemQtyBuy / compare
1Raspberry Pi 4 Model B
about 4000 to 9000 INR
1Robu.in Amazon.in ThinkRobotics
2Official 15 W USB-C power supply (5.1 V, 3 A)
Do not use an old phone charger
1Robu.in Amazon.in ThinkRobotics
3microSD card 32 GB, class 10 / A1 (with Raspberry Pi OS)
And a card reader to write it
1Robu.in Amazon.in ThinkRobotics
4Tactile push button (12 mm, with cap)1Robu.in Amazon.in ThinkRobotics
5SG90 micro servo2Robu.in Amazon.in ThinkRobotics
6Dupont jumper wires, male-to-female, 20 cm (pack of 40)1Robu.in Amazon.in ThinkRobotics
7Breadboard 830 points
For resistors and shared GND / 5 V
1Robu.in Amazon.in ThinkRobotics
← 34. Radar sweep with servo and ultrasonicAll projects36. Automatic gate with ultrasonic sensor →

This is a learning tool. The simulator checks the program logic, not the electrical design. Never put more than 3.3 V on a GPIO pin.