Tetris on Arduino
An Interactive Open-Source Gaming System Using Arduino Mega, WS2812B LED Matrix and Joystick
Gaming Systems • Embedded Systems • LED Matrix • Arduino
An open-source hardware implementation of the classic Tetris game on an Arduino Mega platform. The system drives an 8×16 addressable WS2812B LED matrix display, uses an analog joystick for left/right movement and piece rotation, and displays score and line counts on a secondary I2C LCD.
Abstract
This project presents a fully functional, open-source Tetris gaming console constructed with low-cost microcontrollers and addressable RGB LEDs. The game engine is programmed in C++ for the Arduino Mega 2560, handling matrix collision detection, line clearing algorithms, piece rotation matrices, and score calculation in real time.
The display consists of an 8×16 WS2812B LED panel driven via the FastLED library. User input is processed through a 2-axis analog joystick with push-button functionality, while high scores and game status are displayed on an I2C LCD module.
Components Required
Live Browser Game Simulator
Use the buttons or keyboard arrow keys (Arrow Left/Right to move, Up to rotate, Down to drop, Space to hard drop) to play the simulation.
Arduino Source Code
⬇️ Download Code (.ino)The full C++ Arduino Mega sketch for Tetris using FastLED and LiquidCrystal_I2C libraries.
#include <FastLED.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define LED_PIN 6
#define MATRIX_WIDTH 8
#define MATRIX_HEIGHT 16
#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
CRGB leds[NUM_LEDS];
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int JOYSTICK_X = A0;
const int JOYSTICK_Y = A1;
const int JOYSTICK_SW = 2;
int score = 0;
int level = 1;
int lines = 0;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(40);
FastLED.clear(); FastLED.show();
lcd.init(); lcd.backlight();
lcd.setCursor(0, 0); lcd.print("TETRIS GAME");
lcd.setCursor(0, 1); lcd.print("Press to Start");
pinMode(JOYSTICK_SW, INPUT_PULLUP);
}
void loop() {
FastLED.show();
delay(50);
}
Open-Source Resources
Freely Available for Study and Reproduction
The Tetris on Arduino project is released under open source. You can download the source code, schematics, and component lists below.
OpenSource Section — SB.Chetak Innovation
This project is released for educational and research purposes. You may study, reproduce and modify it in accordance with open-source guidelines.