OLED PONG GAME

by DESHBOT in Circuits > Arduino

15 Views, 0 Favorites, 0 Comments

OLED PONG GAME

WhatsApp Image 2026-09-25 at 9.51.19 AM.jpeg

The OLED Pong Game is a simple two-player-style arcade game made using an Arduino and a 128×64 OLED display.

The game has a player paddle on the left side and a CPU-controlled paddle on the right side. The player controls the left paddle using two push buttons. A ball moves around the screen and bounces from the top and bottom walls and the paddles.

When the ball passes the player's paddle, the CPU gets one point. When the ball passes the CPU paddle, the player gets one point.

Supplies

des 1.jpeg
uno.jpeg
oled.jpeg

Components Required

ComponentQuantity

Deshbot shield

Arduino Uno/Nano

128×64 OLED Display

Push Button

Buzzer

Pin Connections


OLED Display

OLED PinArduino

VCC - 5V

GND - GND

SDA - A4

SCL - A5

Buttons

ButtonArduino

UP Button - D10

DOWN Button - D12

The other terminal of each button is connected to GND.

The program uses INPUT_PULLUP, so an unpressed button reads HIGH and a pressed button reads LOW.

Working Principle

WhatsApp Image 2026-09-25 at 9.51.19 AM.jpeg


The Arduino continuously performs five main operations:

  1. Reads the two player buttons.
  2. Moves the player paddle.
  3. Moves the CPU paddle automatically.
  4. Moves the ball and detects collisions.
  5. Updates the OLED display.

The ball has two movement variables:

  1. ballDX — horizontal movement
  2. ballDY — vertical movement

When the ball hits the top or bottom of the OLED, its vertical direction is reversed.

When the ball hits either paddle, its horizontal direction is reversed.


Player Control

The player uses two buttons:

  1. D10 → Move paddle upward
  2. D12 → Move paddle downward

The program prevents the paddle from moving outside the OLED screen.

if (digitalRead(UP_BUTTON) == LOW) {
playerY -= 3;
}

if (digitalRead(DOWN_BUTTON) == LOW) {
playerY += 3;
}


CPU Paddle

The CPU paddle automatically follows the vertical position of the ball.

If the ball is below the CPU paddle, the CPU moves downward.

If the ball is above the CPU paddle, the CPU moves upward.

This creates a simple computer opponent.


Ball Movement

The ball position is continuously updated:

ballX += ballDX;
ballY += ballDY;

The ball changes direction when it reaches the top or bottom wall.

if (ballY <= 8 || ballY >= SCREEN_HEIGHT - 2) {
ballDY = -ballDY;
}


Paddle Collision

The Arduino checks whether the ball reaches the player's paddle.

If it does, the ball changes its horizontal direction.

The same method is used for the CPU paddle.


Scoring System

There are two score variables:

int playerScore = 0;
int cpuScore = 0;

If the ball goes past the player's paddle:

CPU Score +1

If the ball goes past the CPU paddle:

Player Score +1

After a point is scored, the ball returns to the center.


OLED Display

The OLED displays:

  1. Player score
  2. CPU score
  3. Center dividing line
  4. Player paddle
  5. CPU paddle
  6. Ball

The game screen is refreshed continuously so the movement appears animated.




Downloads

Conclusion


The OLED Pong Game demonstrates how an Arduino can be used to create a simple interactive video game.

The project combines button input, OLED graphics, collision detection, automatic CPU movement and a scoring system into one application. It is a useful beginner-level embedded-system project and can be further developed into a more advanced arcade game.