Play rock-paper-scissors using a time-of-flight sensor and an Arduino UNO R4
Owing to its simplicity and fast-paced nature, rock-paper-scissors is a great game to play with friends, and when it comes to translating it into a digital format, many creative adaptations can be made. This version by madmcu forgoes the typical three-button input scheme in favor of an AI model running on an Arduino UNO R4 Minima and a time-of-flight (ToF) matrix sensor.
While many ToF sensors have a single laser emitter and detector pair, the VL53L5CX contains an 8×8 grid of detectors that allows it to form a very rudimentary image comprised of shorter and longer distances. Because of this fact, madmcu was able to begin his project by capturing a variety of these “images” via the NanoEdge AI Studio and assigning labels for “unknown,” “nothing,” rock,” “paper,” and “scissors” across the dataset. From here, a gesture classification model was trained on the dataset and then exported as an embedded model for use in firmware.
In order to play rock-paper-scissors, the UNO R4 Minima starts by initializing the ToF sensor module and NanoEdge model before entering the main loop. The device continuously grabs new data from the sensor, classifies it, and then checks the value against the computer’s randomized selection to determine the winner. The game continues until either the player or the Arduino reaches three points.
For more information about the process of training a model on ToF data, you can check out madmcu’s Project Hub post here.