Rock Paper Scissors
A webcam game that connects hand gestures to an Arduino-controlled display.
01Problem and solution
Problem
Show how a camera can turn a hand gesture into mechanical motion, in a classroom or at a science fair.
Solution
A Python game reads the player’s gesture from a webcam, picks the computer’s move and sends it over USB serial to an Arduino, which raises one of three wooden servo flaps.
02How it works
Gesture input
OpenCV captures webcam frames. MediaPipe recognises a fist, open palm, or V sign.
Game logic
Python picks a move at random and tracks wins, losses, and draws.
Physical display
The computer sends its move over USB serial, and the Arduino raises one of three servo flaps.
03How I built it
Gesture detection first
Started with the Python side, getting the webcam and MediaPipe’s gesture recognizer to tell rock, paper and scissors apart.
Make recognition reliable
Identifying a gesture and confirming it took time to get right. The game now only accepts a gesture recognised with at least 55% confidence and held for 0.9 seconds, which filters out accidental gestures.
Build the Arduino side
Made three wooden flaps, each on its own servo, and wrote the Arduino sketch that raises the chosen one. Python talks to it over USB serial with a
PING/PONGhandshake, and the start-up and acknowledgments passed simulated tests before the flaps were connected.Play the full game
Ran the complete game with the webcam and the wooden flaps.
04Technical details
- The serial link runs at 9600 baud. The Arduino lifts the chosen flap from 10° to 90° for 1.5 seconds, lowers it, then replies
OKwith the move so the game knows the display has finished. - The sketch buffers incoming commands and rejects any that are unknown or too long.
- Command-line options select the webcam and serial port, and a
--no-arduinomode allows webcam-only play.
05Engineering areas
Computer vision
The game checks recognition confidence and waits for a brief hold before accepting a move.
Embedded systems
Arduino C++ runs the flap’s lift-and-return sequence and sends an acknowledgment.
06Real-world use
Classroom or science fair
Show how a camera can turn a hand gesture into mechanical motion.
07Code excerpt
void raiseFlap(Servo &selectedServo, const char *moveName) {
lowerAllFlaps();
selectedServo.write(RAISED_ANGLE);
delay(RAISED_TIME_MS);
selectedServo.write(REST_ANGLE);
Serial.print("OK ");
Serial.println(moveName);
}
void handleCommand(const char *command) {
if (strcmp(command, "PING") == 0) {
Serial.println("PONG");
} else if (strcmp(command, "ROCK") == 0) {
raiseFlap(rockServo, "ROCK");
} else if (strcmp(command, "PAPER") == 0) {
raiseFlap(paperServo, "PAPER");
} else if (strcmp(command, "SCISSORS") == 0) {
raiseFlap(scissorsServo, "SCISSORS");
} else {
Serial.print("UNKNOWN ");
Serial.println(command);
}
}