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.

Parts in this circuit
| Part | Type |
|---|---|
| Base servo | Servo |
| Gripper servo | Servo |
| Start cycle | Push 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.
| # | Colour | From (part and leg) | To (header pin) |
|---|---|---|---|
| 1 | Coloured | Base servo - signal | Pin 11 (GPIO17) |
| 2 | Red | Base servo - 5 V | Pin 2 (5V) |
| 3 | Black | Base servo - GND | Pin 6 (GND) |
| 4 | Coloured | Gripper servo - signal | Pin 12 (GPIO18) |
| 5 | Red | Gripper servo - 5 V | Pin 4 (5V) |
| 6 | Black | Gripper servo - GND | Pin 9 (GND) |
| 7 | Coloured | Start cycle - Signal | Pin 13 (GPIO27) |
| 8 | Black | Start cycle - GND | Pin 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
- move() sets both servo angles and then waits one second for the arm to get there.
- Each call to move() is one pose. The cycle is five poses in order.
- wait_for_press() pauses the program until the button is pressed, so the cycle runs once per press.
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.
| # | Item | Qty | Buy / compare |
|---|---|---|---|
| 1 | Raspberry Pi 4 Model B about 4000 to 9000 INR | 1 | Robu.in Amazon.in ThinkRobotics |
| 2 | Official 15 W USB-C power supply (5.1 V, 3 A) Do not use an old phone charger | 1 | Robu.in Amazon.in ThinkRobotics |
| 3 | microSD card 32 GB, class 10 / A1 (with Raspberry Pi OS) And a card reader to write it | 1 | Robu.in Amazon.in ThinkRobotics |
| 4 | Tactile push button (12 mm, with cap) | 1 | Robu.in Amazon.in ThinkRobotics |
| 5 | SG90 micro servo | 2 | Robu.in Amazon.in ThinkRobotics |
| 6 | Dupont jumper wires, male-to-female, 20 cm (pack of 40) | 1 | Robu.in Amazon.in ThinkRobotics |
| 7 | Breadboard 830 points For resistors and shared GND / 5 V | 1 | Robu.in Amazon.in ThinkRobotics |
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.