Source: https://mokxi.com/learn/arduino-game-projects

Learn

# Arduino game projects, from a first button to a full arcade cabinet

Intermediate

Written by the Mokxi team

Start building free Open the editor

Or see every lesson.

- 455 parts on the bench
- 43 boards running now
- 1.00x real time, on every board

Hold the button

The Reaction timer example: wait for the light, press the button, and read your time in milliseconds.

Games are the best reason to learn Arduino. They need inputs, outputs, timing and a little logic, and when one works you know it right away, because you can play it. Every game on this page is already built in Mokxi and runs in your browser, so you can play it first, then open the code and change it, before you spend anything on parts.

The circuit above is the easiest of them, a reaction timer: wait for the lamp, press the button, and the serial monitor tells you how many milliseconds you took. It is one lamp, one button and two small buzzers, and it already has the thing every game needs, a wait the player cannot predict: somewhere between 1.5 and 4 seconds.

They are listed from easiest to hardest. Each one says what it teaches, so you can pick by what you want to learn next.

## Beginner: one or two buttons

Reaction timer. One lamp and one button. It teaches millis() for timing, random() for the wait, and how to catch a player who presses too early: the serial monitor says "too soon" and the round is thrown away. Change the code to keep a best time, or to average five tries.

Reaction duel. Two players, two buttons, three lamps and a piezo: the Uno lights the middle lamp and the first press wins. It is the reaction timer plus a little more logic, and it is a hit in a classroom.

Electronic dice. Press a button and a number tumbles onto a seven-segment display. It teaches lookup tables, since each digit is a pattern of seven segments.

Tug of war. Two players mash two arcade buttons, and a light on a strip of 15 NeoPixels moves toward whoever presses faster. It runs on an Arduino Nano and teaches counting a press once, on the edge from up to down, so holding a button does not cheat.

Stop the light. A red light runs round a ring of 16 NeoPixels, and you press as it lands on the green one. It runs on a Raspberry Pi Pico and gets faster every level. It teaches working out a position from the time with millis().

## Intermediate: arrays and timing

Simon says. Four LEDs and four buttons: watch a sequence, press it back, and it grows by one each round. It teaches arrays, loops and the idea of game state. The guide has the full sketch and the four mistakes that break it.

Whack-a-mole. Four lamps, four buttons, a buzzer and a score display in a thirty-second round that speeds up as you score. This is the one that teaches doing several things at once with millis(), which every bigger project needs.

Rhythm game. Notes fall down four lanes of an LED panel to a tune, and you hit the lit buttons on the beat. It is whack-a-mole with a song driving the timing.

Arcade button Simon. Simon on an Uno with four lit arcade buttons and a piezo: a note per color, a three second time limit, a faster pace as it grows and the best round kept in the EEPROM.

Dino game. The offline dinosaur game from a web browser, on a 16x2 I2C LCD with one button. The dinosaur and the cacti are custom characters, and the button is read on an interrupt so a quick tap is never missed.

## Advanced: a moving picture

Snake. Two 8x8 LED matrices and a thumb stick. The snake is a ring buffer of cells, moved by writing a new head and erasing the old tail. It teaches data structures on a board with 2 KB of RAM.

Stacker. The arcade cabinet: a row slides, one button drops it, and the overhang is cut off. Two cascaded LED matrices on three wires, with the game itself one AND per drop. It is the most opened example in Mokxi.

Pong. A paddle game on a color TFT with a thumb stick and a piezo, at a frame rate an Uno can keep up with by redrawing only what moved. There is an OLED version too.

Breakout. 32 bricks on a 128x64 OLED, a knob for the paddle and three lives, on an Arduino Mega. Where the ball hits the paddle sets its angle, and the ball moves in sixteenths of a pixel so it needs no floating point.

Flappy Bird. One button flaps a bird through gaps in the pipes on a 128x64 OLED, on an Uno. Gravity is a number added to the speed every frame, and each pipe draws only the columns it moves into, so the Uno keeps up.

Space Invaders. Eighteen invaders on an OLED march faster as you shoot them, with three buttons to move and fire. Each row of invaders is one byte, a bit per invader, which is how a whole wave fits in three bytes.

Tetris. Two 8x8 LED matrices stacked into a field 8 wide and 16 tall, on an Arduino Mega with four buttons. The field is sixteen bytes and each piece is a 16-bit number, so a full row is 0xFF and a collision is an AND.

## What makes a game work on a microcontroller

A loop that never waits long. A game reads its buttons, moves things, and draws, many times a second. A long delay() in the middle means presses are missed. Every game here times itself with millis() instead, keeping a "next time" for each thing that moves.

Inputs that count once. A button that is held down for 200 ms is seen in dozens of passes of the loop. Games count the change from up to down, and they give the contacts a few milliseconds to stop bouncing.

Randomness that is really random. An Arduino with no clock starts its random number generator in the same place every time. Seed it from micros() at the first button press, when a person’s timing decides the number.

Drawing only what changed. An LED matrix, an OLED or a TFT takes time to fill. Snake changes two dots per step, pong erases and redraws the paddle and ball, and both stay fast because of it.

## Playing them in a class or a club

Games make a strong unit for a coding class or an after school club, because students want to finish them. A good order is reaction timer, then Simon, then whack-a-mole, then a free choice. Each one runs on a Chromebook in the browser, and a student can open and play it without an account; saving work and joining a class need one.

For a teacher, each game can be a starter project: hand out the working version, and ask for one change, such as a high score, a time limit, sound, or a two player mode. That is a real programming task with a result anyone can test by playing it.

## From the browser to real parts

Every game here uses common parts: LEDs, pushbuttons, a passive buzzer, MAX7219 matrix modules, a TM1637 display, an SSD1306 OLED or an ILI9341 TFT, and a thumb stick. The sketches are ordinary Arduino code, and the libraries they use are the ones in the Arduino Library Manager, so the code you change in the browser is the code you upload to a real board.

A few examples use small helper headers that come with Mokxi, such as mokxi_max7219.h; each guide names the usual library to use on a real board instead.

## Questions

What is the easiest game to make with Arduino?

A reaction timer: one LED, one button, and millis() to measure how long you took after the light came on. It teaches timing and random numbers in a short sketch.

Can I make games on an Arduino with an LCD or OLED screen?

Yes. A 16x2 LCD suits text games and simple side scrollers, and a 128x64 OLED is enough for pong, snake and many arcade games. Mokxi has an OLED pong you can play and edit.

Can I play Arduino games online without hardware?

Yes. Every game on this page runs in Mokxi in your browser, with the real sketch compiled and running on a simulated board. Press Run, then use the buttons and stick with the mouse.

Which Arduino is best for games?

An Uno or Nano is enough for LED games, matrices, OLED pong and snake. For color screens with lots of movement, an ESP32 has far more speed and memory.

Related

## Keep going

Arduino Simon Says Game: Four LEDs, Four Buttons Arduino Whack-a-Mole Game: LEDs, Buttons, Score Arduino Snake Game on an 8x8 LED Matrix (MAX7219) Arduino Stacker Arcade Game on Two LED Matrices Arduino Projects for Beginners, Each One Running Reaction Time Science Fair Project With an Arduino The game design course Arcade button Simon on an Uno Intermediate The dino game on an I2C LCD Intermediate Tug of war on a Nano Beginner Breakout on an OLED Advanced Stop the light on a Pico Beginner Flappy Bird on an OLED Intermediate Space Invaders on an OLED Advanced Tetris on two LED matrices Advanced Every example project The Arduino simulator The project page, with the full sketch Intermediate

## Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.

Start building free Open the editor
