🁢 Build a Domino-Placing Robot with Raspberry Pi!
Meet your new robot helper that can see a line of dominoes with its camera "eye" and place new ones perfectly — powered by a Raspberry Pi, a servo motor, and the Pi Camera Module.
What You'll Build
This robot uses a Pi Camera as its "eye" to look at a row of dominoes already on the table, a Raspberry Pi as its "brain" to figure out where the next domino should go, and a servo motor as its "arm" to gently tip a new domino into place — one at a time, building a long domino chain all by itself!
🎯 Why Kids Love This Robotics Project
This is a brilliant Raspberry Pi robotics project for kids because it combines three exciting ideas in one build: a camera that "sees", a servo motor that moves, and a tiny computer that makes decisions in between. It's a gentle, hands-on introduction to computer vision and robotics — way more fun than a worksheet!
🧰 Materials You Need
🛠️ Step-by-Step Building Instructions
Build the Robot Frame
Cut a sturdy base from cardboard or a wooden board. This base will hold the Raspberry Pi, the servo arm, and the camera mount steady while the robot works.
Mount the Pi Camera
Fix the Pi Camera Module on a small stand so it points down and forward at the table where the dominoes will be placed — like a bird's-eye view of the construction zone.
Build the Servo "Arm"
Attach a flat lever (a craft stick or 3D-printed paddle) to the servo's rotating arm. This paddle will gently push each new domino upright into its spot.
Set Up the Domino Feeder
Create a simple ramp or slot (a folded piece of cardboard works!) that holds a stack of dominoes and drops one at a time into position in front of the servo arm.
Connect the Servo to the Pi
Wire the servo's signal, power, and ground wires to the Raspberry Pi's GPIO pins, following the circuit diagram below.
Connect the Pi Camera
Carefully slide the camera ribbon cable into the Pi's CSI camera port (the blue side faces the USB ports) and lock the clip gently.
Install Software
On the Raspberry Pi, enable the camera in raspi-config and install the picamera2, opencv-python, and gpiozero libraries.
Upload the Code & Test
Run the Python program below. It checks the camera image for the last domino's position, then tells the servo arm to place the next one at the right spot and angle!
🔌 Circuit Diagram
Layout:
RASPBERRY PI (GPIO header)
┌────────────────────┐
│ 5V ●──────┬──────┼── Servo Power (red)
│ GND ●──┬───┼──────┼── Servo Ground (brown)
│ GPIO17●─┼───┼──────┼── Servo Signal (orange)
└────────────────────┘
│ │
CSI Camera Port
(Pi Camera ribbon cable)
| Component | Wire | Raspberry Pi Connection |
|---|---|---|
| Servo Motor | Signal (orange/yellow) | GPIO 17 |
| Servo Motor | Power (red) | 5V pin |
| Servo Motor | Ground (brown/black) | GND pin |
| Pi Camera Module | Ribbon cable | CSI Camera Port |
Tip: If your servo shakes the Raspberry Pi's power, use a separate 5V/2A power source for the servo and connect its ground to the Pi's ground.
💻 Python Code
domino_robot.pyfrom gpiozero import Servo
from picamera2 import Picamera2
import cv2
import time
# ---- Setup the servo "arm" ----
arm = Servo(17) # GPIO 17
# ---- Setup the Pi Camera ----
camera = Picamera2()
camera.configure(camera.create_preview_configuration())
camera.start()
time.sleep(2) # let the camera warm up
def find_last_domino_position(frame):
"""
Looks at the camera image and finds the rightmost
dark rectangle (the last placed domino).
Returns the x-position (in pixels) of that domino.
"""
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
_, thresh = cv2.threshold(gray, 80, 255, cv2.THRESH_BINARY_INV)
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
last_x = 0
for c in contours:
x, y, w, h = cv2.boundingRect(c)
if w * h > 200: # ignore tiny noise
last_x = max(last_x, x + w)
return last_x
def place_domino():
"""Swing the servo arm forward to push a new domino upright."""
arm.value = -1 # pull back to "ready" position
time.sleep(0.4)
arm.value = 1 # push forward to stand the domino up
time.sleep(0.4)
arm.value = 0 # return to neutral
time.sleep(0.4)
print("Domino robot starting... press CTRL+C to stop.")
try:
while True:
frame = camera.capture_array()
last_x = find_last_domino_position(frame)
# If there is room on the table, place the next domino
if last_x < frame.shape[1] - 50:
place_domino()
print("Placed a new domino! Last position:", last_x)
time.sleep(1) # give it time to settle
else:
print("Reached the end of the table. Chain complete!")
break
except KeyboardInterrupt:
print("Stopping robot.")
finally:
camera.stop()
🌟 Tips for a Better Domino Robot
- Use good, even lighting so the camera can clearly see the dark dominoes against a light table.
- Start with bigger, chunkier dominoes — they're easier for the servo arm to handle precisely.
- Keep the camera mount very still; even small wobbles can confuse the position detection.
- Test the servo arm's push motion on its own first, before adding the camera logic.
- Place a contrasting mat (e.g., white table, dark dominoes) for the easiest computer vision results.
❓ Frequently Asked Questions
Do I need to know Python to build this?
A little helps, but the code above is ready to copy and run. Beginners can install the libraries, upload the code, and start experimenting from there.
Which Raspberry Pi model works best?
Raspberry Pi 4 or 5 are great for smooth camera processing, but a Pi 3B+ will also work for this beginner-level project.
Can I use a webcam instead of the Pi Camera?
Yes! You can swap picamera2 for OpenCV's cv2.VideoCapture(0) if you're using a USB webcam instead.
What age group is this project good for?
With an adult's help for wiring and software setup, kids aged 10 and up can enjoy building and coding this project.
🏆 You Did It!
You just built a robot that can see, think, and build with dominoes — all on its own! Try changing the domino spacing, adding curves to the chain, or even teaching it to place dominoes in a spiral pattern.

Comments
Post a Comment