|
Arduino Nano R3 |
x 1 | |
|
I2C 16x2 Arduino LCD Display Module |
x 1 | |
|
Buzzer |
x 1 | |
|
PUSHBUTTON |
x 2 | |
|
LED |
x 10 | |
|
Resistor, 470 ohm |
x 10 | |
|
Resistor 10k ohm |
x 2 |
![]() |
arduino IDEArduino
|
|
![]() |
Soldering Iron Kit |
DIY addictive Arduino 1D Pong game
Pong is a table tennis–themed 2 dimensional graphics arcade video game manufactured by Atari and originally released on 1972.
This time I will present you a simple way to make a 1D LED Pong game which is an interesting project that simulates a Pong game on a single-dimensional array of LEDs. This can be done using Arduino microcontroller board. The movement of the ball is simulated by the array of LEDs, and the paddles are the two buttons. The game is for 2 players, in which the "ball" travels down the length of the LED array, and will bounce back if the button is pressed when yellow LED is illuminated.
The result is displayed on the LCD screen. The movement of the ball, the winning of a point as well as the victory are accompanied by appropriate sounds
The device is very simple to make and consists of several components:
- Arduino Nano microcontroller board
- 16x2 LCD Display
- 10 Leds
- 12 resistors
- two buttons
- and Buzzer
The game starts by moving the ball from player 1 to player 2, and if player 2 fails to press the button while the yellow LED is on, the red LED will light up and it's a point for player 1. Each game is started by the winner of the previous one. The speed of the ball is increases after every hit, making it more difficult to hit the ball in time. The match ends when one of the players wins 10 games, and at that moment the Leds that are on the winner's side will flash.
- The starting speed of movement of the LEDs is set in the row:
const unsigned long initialMillisecondsPerLED = 400;
The lower this number, the faster the movement speed
- The degree of acceleration after each hit is adjusted in the rows:
if (deltaMillisecondsPerLED > 50)
{
deltaMillisecondsPerLED -= 50;
and the higher this number is, the higher the acceleration.
The game can be played by one or two players. In the case of two players, which is a natural option, it is preferable to use robust external arcade buttons.
For this purpose I used these buttons that I made for the needs of one of my previous projects. They are large, and have a precise, and audible click.
Finally a short conclusion. This is an interesting one-dimensional compact version of the classic "Pong" game made with a minimal number of components, yet extremely addictive, and can be played for hours before you get bored. The device is mounted in a suitable box made of PVC board and lined with self-adhesive wallpaper. For power, it is preferable to use a lithium battery for the sake of mobility
//#include <LiquidCrystal.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); bool willTheBallGoTowardsPlayerTwo = true; bool isInputAllowed = true; const int playerOne = 12; const int goalPlayerOne = 13; const int buttonPlayerOne = 3; const int playerTwo = 5; const int goalPlayerTwo = 4; const int buttonPlayerTwo = 2; int scoreOfPlayerOne = 0; int scoreOfPlayerTwo = 0; const unsigned long initialMillisecondsPerLED = 400; const unsigned long initialDeltaMillisecondsPerLED = 50; unsigned long millisecondsPerLED = initialMillisecondsPerLED; unsigned long deltaMillisecondsPerLED = initialDeltaMillisecondsPerLED; unsigned long currentMillis = 0; unsigned long previousMillis = 0; int currentPosition = playerOne; //Player one starts the game. int previousPosition = playerOne + 1; int deltaPosition = 0; int buttonStatePlayerOne = 0; int lastButtonStatePlayerOne = 0; int buttonStatePlayerTwo = 0; int lastButtonStatePlayerTwo = 0; void setup() { lcd.backlight(); lcd.begin(16,2); lcd.clear(); lcd.setCursor(2, 0); lcd.print("1D-Pong Game"); lcd.setCursor(3, 1); lcd.print("by mircemk"); delay(2000.); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player One: 0"); lcd.setCursor(0, 1); lcd.print("Player Two: 0"); pinMode(4, 1); pinMode(5, 1); pinMode(6, 1); pinMode(7, 1); pinMode(8, 1); pinMode(9, 1); pinMode(10, 1); pinMode(11, 1); pinMode(12, 1); pinMode(13, 1); /*Connect pins 4 to 13 to 220ohm resistors, connect the LEDs' longer legs(+) to the resistors, connect the other legs(-) of the LEDs' to ground. I recommend red LEDs for 4 and 13(Goals), yellow LEDs for 5 and 12(Players), green LEDs for other pins(Field). */ pinMode(2, 0); //Pushbuttons for players. Pin 2 is for player two. Pin 3 is for player one. pinMode(3, 0); //Connect pushbuttons following the instructions on this page: https://www.arduino.cc/en/Tutorial/DigitalReadSerial } void loop() { ListenForInput(); currentMillis = millis(); if (currentMillis - previousMillis >= millisecondsPerLED) //If you don't understand this, see: https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay { CheckGoalConditions(); lcd.clear(); lcd.setCursor(0, 0); //(Column,Row) lcd.print("Player One: "); lcd.setCursor(12, 0); lcd.print(scoreOfPlayerOne); lcd.setCursor(0, 1); //(Column,Row) lcd.print("Player Two: "); lcd.setCursor(12, 1); lcd.print(scoreOfPlayerTwo); CheckEndGame(); DetermineNextPosition(); MoveBallToNextPosition(); previousMillis = currentMillis; } } void ListenForInput() //If you don't understand this method. See: https://www.arduino.cc/en/Tutorial/StateChangeDetection { buttonStatePlayerOne = digitalRead(buttonPlayerOne); buttonStatePlayerTwo = digitalRead(buttonPlayerTwo); if (buttonStatePlayerOne != lastButtonStatePlayerOne && isInputAllowed) { if (buttonStatePlayerOne == 1) { if (currentPosition == playerOne) { ToggleBallDirection(); IncreaseSpeed(); } else { ScoreForPlayer(2); } } lastButtonStatePlayerOne = buttonStatePlayerOne; } if (buttonStatePlayerTwo != lastButtonStatePlayerTwo && isInputAllowed) { if (buttonStatePlayerTwo == 1) { if (currentPosition == playerTwo) { ToggleBallDirection(); IncreaseSpeed(); } else { ScoreForPlayer(1); } } lastButtonStatePlayerTwo = buttonStatePlayerTwo; } } void ToggleBallDirection() { willTheBallGoTowardsPlayerTwo = !willTheBallGoTowardsPlayerTwo; isInputAllowed = false; //Only one direction change per frame is allowed for consistent gameplay. } void IncreaseSpeed() { millisecondsPerLED -= deltaMillisecondsPerLED; if (deltaMillisecondsPerLED > 50) //Because of this, it takes a little more time to reach to an insane speed. Adjust or remove this if rounds become too long. { deltaMillisecondsPerLED -= 50; } } void MoveBallToNextPosition() //Moves the ball one spot. { previousPosition = currentPosition; digitalWrite(previousPosition, 0); currentPosition = currentPosition + deltaPosition; digitalWrite(currentPosition, 1); tone(1, 500, 50); isInputAllowed = true; } void DetermineNextPosition() { if (willTheBallGoTowardsPlayerTwo) { deltaPosition = -1; } else { deltaPosition = 1; } } void CheckGoalConditions() { if (currentPosition == goalPlayerTwo) { ScoreForPlayer(1); } else if (currentPosition == goalPlayerOne) { ScoreForPlayer(2); } } void ScoreForPlayer(int playerWhoScored) { isInputAllowed = false; FlashAllLEDs(1, 0); if (playerWhoScored == 1) { scoreOfPlayerOne++; Reset(1); } else if (playerWhoScored == 2) { scoreOfPlayerTwo++; Reset(2); } } void CheckEndGame() { if (scoreOfPlayerOne == 10) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player One Win"); EndGameCeremonyFor(1); } if (scoreOfPlayerTwo == 10) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player Two Win"); EndGameCeremonyFor(2); } } void Reset(int playerCurrentlyScored) { if (playerCurrentlyScored == 1) { digitalWrite(playerOne, 1); currentPosition = playerOne; willTheBallGoTowardsPlayerTwo = true; tone(1, 200 ,150 ); } else if (playerCurrentlyScored == 2) { digitalWrite(playerTwo, 1); currentPosition = playerTwo; willTheBallGoTowardsPlayerTwo = false; tone(1, 300 ,150 ); } delay(1000); //Are three seconds enough for players to process the score? millisecondsPerLED = initialMillisecondsPerLED; //Sets speed to initial value at the beginning of each round. deltaMillisecondsPerLED = initialDeltaMillisecondsPerLED; } void EndGameCeremonyFor(int winner) { FlashAllLEDs(50, winner); TurnOffAllLEDsForPlayer(0); scoreOfPlayerOne = 0; scoreOfPlayerTwo = 0; delay(1000); lcd.clear(); lcd.setCursor(4, 0); lcd.print("Starting"); lcd.setCursor(4,1); lcd.print("New Game"); delay(2000); } void TurnOnAllLEDsForPlayer(int player) { if (player != 1) //When this method is called with (2), only these pins(player two's) will turn on { digitalWrite(4, 1); digitalWrite(5, 1); digitalWrite(6, 1); digitalWrite(7, 1); digitalWrite(8, 1); tone(1, 1000, 35); } if (player != 2) //When this method is called with (1), only these pins(player one's) will turn on { digitalWrite(9, 1); digitalWrite(10, 1); digitalWrite(11, 1); digitalWrite(12, 1); digitalWrite(13, 1); tone(1, 1000, 35); } } void TurnOffAllLEDsForPlayer(int player) { if (player != 1) //When this method is called with (2), only these pins(player two's) will turn off { digitalWrite(4, 0); digitalWrite(5, 0); digitalWrite(6, 0); digitalWrite(7, 0); digitalWrite(8, 0); } if (player != 2) //When this method is called with (1), only these pins(player one's) will turn off { digitalWrite(9, 0); digitalWrite(10, 0); digitalWrite(11, 0); digitalWrite(12, 0); digitalWrite(13, 0); } } void FlashAllLEDs(int blinkCount, int player) //Second parameter(int player) is for when you want to flash only one player's LEDs. Use 1 for player one, use 2 for player two. { for (int i = 0; i < blinkCount; i++) { TurnOnAllLEDsForPlayer(player); delay(35); TurnOffAllLEDsForPlayer(player); delay(35); } }
DIY addictive Arduino 1D Pong game

Raspberry Pi 5 7 Inch Touch Screen IPS 1024x600 HD LCD HDMI-compatible Display for RPI 4B 3B+ OPI 5 AIDA64 PC Secondary Screen(Without Speaker)
BUY NOW
ESP32-S3 4.3inch Capacitive Touch Display Development Board, 800×480, 5-point Touch, 32-bit LX7 Dual-core Processor
BUY NOW
Raspberry Pi 5 7 Inch Touch Screen IPS 1024x600 HD LCD HDMI-compatible Display for RPI 4B 3B+ OPI 5 AIDA64 PC Secondary Screen(Without Speaker)
BUY NOW- Comments(0)
- Likes(1)

-
(DIY) C64iSTANBUL Jul 15,2024
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Mirko Pavleski
-
DIY ESP32 Bioresonance Rife Machine with ZAPPER function Rife machine therapy is an alternative treatment developed by Dr. Royal Raymond Rife in the 1930s. H...
-
Arduino VFO Project with a Large LCD Display A Variable Frequency Oscillator (VFO) is an electronic oscillator whose output frequency can be adj...
-
Exploring the Tesla Coil Driver Board, Full Review & Test Results Some time ago I presented you a video in which I analyzed a super cheap Tesla Coil driver that cost...
-
Arduino Eatrthquake alarm and protection system with D7S seismic Sensor Earthquakes are extremely common events around the world. On average, there are fifty earthquakes a...
-
Review and Comparison of Three Inexpensive Metal Detector Kits A metal detector is a device used to detect the presence of metal objects in the ground or other ma...
-
How to make simple Arduino RGB Led strip VU Meter VU meter or volume unit meter is a device intended for visual presentation of the audio signal. It ...
-
Arduino 3D Printed self Balancing Cube Self-balancing devices are electronic devices that use sensors and motors to keep themselves balanc...
-
OpenWebRX - Simplest Rasprberry Pi + RTLSDR Web SDR Radio Software-Defined Radio is a radio communication system where components that have traditionally bee...
-
Colorful Arduino Tetris Game - WS2812B LED Matrix Tutorial Tetris is a puzzle video game created in 1985 by Alexey Pajitnov. Players manipulate falling geomet...
-
Ultra cheap Ultrasonic levitation Device - functionality and testing Ultrasonic levitation is phenomenon where objects are suspended in mid-air using the power of sound ...
-
DIY -Spirit PI- ESP32 + Smartphone Sensitive Metal Detector Pulse Induction (PI) metal detector operates on a principle based on sending short pulses of electr...
-
ESP32 Analog style VU meter with GC9A01 Round Dispalys + Peak Meters A typical VU meter measures audio signals and displays them with a visual indicator. In the classic...
-
Arduino two weel self Balancing Robot Self Balancing Robot is device that can balance itself from falling to the ground. Its function is ...
-
ELECROW CrowPanel ESP32 4.2” E-paper Wi-Fi Info-Dispaly Project An e-paper display (also known as an electronic paper display or E Ink display) is a type of screen...
-
ESP32 Fluid simulation on 16x16 Led Matrix Fluid simulation is a way of replicating the movement and behavior of liquids and gases in differen...
-
Simple GU50 VTTC Tesla Coil with MOT (25+cm Spark) Vacuum Tube Tesla Coils are a common choice for homebuilders for several practical reasons. At Soli...
-
Hourglass ESP8266 Code A hourglass, also known as an sand clock, is a device used to measure the passage of time. It consi...
-
Tug of War Arduino Game on WS2812 Led strip A Tug of War is a classic team-based game where two opposing teams compete to pull a rope in opposi...
-
DIY ESP32 Bioresonance Rife Machine with ZAPPER function Rife machine therapy is an alternative treatment developed by Dr. Royal Raymond Rife in the 1930s. H...
-
Arduino VFO Project with a Large LCD Display A Variable Frequency Oscillator (VFO) is an electronic oscillator whose output frequency can be adj...
-
Exploring the Tesla Coil Driver Board, Full Review & Test Results Some time ago I presented you a video in which I analyzed a super cheap Tesla Coil driver that cost...
-
Arduino Eatrthquake alarm and protection system with D7S seismic Sensor Earthquakes are extremely common events around the world. On average, there are fifty earthquakes a...
-
Review and Comparison of Three Inexpensive Metal Detector Kits A metal detector is a device used to detect the presence of metal objects in the ground or other ma...
-
How to make simple Arduino RGB Led strip VU Meter VU meter or volume unit meter is a device intended for visual presentation of the audio signal. It ...
-
Arduino 3D Printed self Balancing Cube Self-balancing devices are electronic devices that use sensors and motors to keep themselves balanc...
-
OpenWebRX - Simplest Rasprberry Pi + RTLSDR Web SDR Radio Software-Defined Radio is a radio communication system where components that have traditionally bee...
-
Colorful Arduino Tetris Game - WS2812B LED Matrix Tutorial Tetris is a puzzle video game created in 1985 by Alexey Pajitnov. Players manipulate falling geomet...
-
Ultra cheap Ultrasonic levitation Device - functionality and testing Ultrasonic levitation is phenomenon where objects are suspended in mid-air using the power of sound ...
-
DIY -Spirit PI- ESP32 + Smartphone Sensitive Metal Detector Pulse Induction (PI) metal detector operates on a principle based on sending short pulses of electr...
-
ESP32 Analog style VU meter with GC9A01 Round Dispalys + Peak Meters A typical VU meter measures audio signals and displays them with a visual indicator. In the classic...
-
-
-
Modifying a Hotplate to a Reflow Solder Station
938 1 6 -
MPL3115A2 Barometric Pressure, Altitude, and Temperature Sensor
476 0 1 -
-
Nintendo 64DD Replacement Shell
407 0 2 -
V2 Commodore AMIGA USB-C Power Sink Delivery High Efficiency Supply Triple Output 5V ±12V OLED display ATARI compatible shark 100W
1179 4 2 -
How to measure weight with Load Cell and HX711
728 0 3