PYTHONSERIALARDUINO9600 BAUD · OK ACKPIN 8ROCKPIN 990°PAPERPIN 10SCISSORS
FIG. 01Schematic of the system, drawn from the project’s documented parts, pins and code.

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

  1. Gesture input

    OpenCV captures webcam frames. MediaPipe recognises a fist, open palm, or V sign.

  2. Game logic

    Python picks a move at random and tracks wins, losses, and draws.

  3. Physical display

    The computer sends its move over USB serial, and the Arduino raises one of three servo flaps.

03How I built it

  1. Gesture detection first

    Started with the Python side, getting the webcam and MediaPipe’s gesture recognizer to tell rock, paper and scissors apart.

  2. 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.

  3. 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 / PONG handshake, and the start-up and acknowledgments passed simulated tests before the flaps were connected.

  4. 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 OK with 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-arduino mode 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

rockpaperscissor.inoArduino C++
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);
  }
}
The Arduino side of the serial protocol: each command raises one flap and replies with an acknowledgment.