OLED PONG GAME
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
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
The Arduino continuously performs five main operations:
- Reads the two player buttons.
- Moves the player paddle.
- Moves the CPU paddle automatically.
- Moves the ball and detects collisions.
- Updates the OLED display.
The ball has two movement variables:
- ballDX — horizontal movement
- 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:
- D10 → Move paddle upward
- D12 → Move paddle downward
The program prevents the paddle from moving outside the OLED screen.
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:
The ball changes direction when it reaches the top or bottom wall.
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:
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:
- Player score
- CPU score
- Center dividing line
- Player paddle
- CPU paddle
- 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.