Header Ads

Header ADS

🎮 DIY Arduino Nano Snake Game Console with OLED Display and Buttons

 🎮 DIY Arduino Nano Snake Game Console with OLED Display and Buttons

Do you love retro games? Want to build your own handheld Snake game console? Today, I'm going to show you how to make a DIY Snake Game Console using an Arduino Nano, 0.96” OLED Display, and just 4 buttons! Let’s dive into this fun and educational electronics project. 💡

$5 for 10 $5 10pcs 1-2 layer PCB Order from PCBWay: https://www.pcbway.com/?from=technology4power

Welcome to the PCBWay 11th Badge Design Contest!

Are you passionate about PCB design and creativity? PCBWay is back with its 11th Badge Design Contest, inviting electronics enthusiasts, engineers, and designers to showcase their skills by creating unique and innovative badge designs.

This contest is a fantastic opportunity to unleash your imagination, push the boundaries of PCB art, and win exciting prizes. Whether you're a hobbyist or a professional, PCBWay provides the perfect platform to share your designs with a global community.

Interested? Check out the contest details here: PCBWay 11th Badge Design Contest. Get started today and make your mark in the world of creative PCB design! 🚀

🧰 Components Needed

  1. Arduino Nano

  2. OLED Display (0.96” I2C)

  3. 4 Push Buttons

  4. 4 × 10KΩ Resistors

  5. Breadboard & Jumper Wires

  6. USB Cable for Programming


🔌 Wiring Diagram

Below is the wiring diagram for connecting the components. Make sure you follow this properly:

$5 for 10 $5 10pcs 1-2 layer PCB Order from PCBWay: https://www.pcbway.com/?from=technology4power


OLED Display:

  1. GND → Arduino GND

  2. VCC → Arduino 5V

  3. SCL → Arduino A5

  4. SDA → Arduino A4

Buttons (with Pull-up Resistors):

  1. UP → Arduino D2

  2. LEFT → Arduino D3

  3. RIGHT → Arduino D4

  4. DOWN → Arduino D5

Each button is connected with a 10K pull-down resistor to ensure stable readings.


💻 Arduino Code

You can copy and paste the code below directly into your Arduino IDE. This code draws a Snake game on the OLED display and lets you control it using the 4 buttons.


#include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Button pins #define UP_BTN 2 #define LEFT_BTN 3 #define RIGHT_BTN 4 #define DOWN_BTN 5 // Debounce timing unsigned long lastInputTime = 0; const unsigned long debounceDelay = 100; // Snake grid and logic #define GRID_SIZE 4 #define MAX_LENGTH 64 int snakeX[MAX_LENGTH]; int snakeY[MAX_LENGTH]; int length = 3; int dirX = 1; int dirY = 0; int foodX, foodY; bool gameOver = false; void setup() { Serial.begin(9600); pinMode(UP_BTN, INPUT_PULLUP); pinMode(LEFT_BTN, INPUT_PULLUP); pinMode(RIGHT_BTN, INPUT_PULLUP); pinMode(DOWN_BTN, INPUT_PULLUP); if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("OLED failed")); while (1); } display.clearDisplay(); display.display(); snakeX[0] = 64; snakeY[0] = 32; snakeX[1] = 60; snakeY[1] = 32; snakeX[2] = 56; snakeY[2] = 32; generateFood(); } void loop() { if (gameOver) { display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(30, 30); display.println("Game Over!"); display.display(); delay(3000); resetGame(); } handleInput(); moveSnake(); checkCollision(); drawGame(); delay(150); } // Remaining functions: handleInput(), moveSnake(), generateFood(), checkCollision(), drawGame(), resetGame() // (Included in full in the downloadable code)

🔗 You can find the full code here or copy it from the post above.

🕹 How It Works

  1. The snake moves on a grid drawn on the OLED screen.

  2. You control its direction using 4 buttons (UP, DOWN, LEFT, RIGHT).

  3. The snake grows longer every time it eats food.

  4. The game ends if the snake hits the wall or itself.


🧠 Tips

  1. You can increase the difficulty by reducing the delay in the loop() function.

  2. Add a score system and show it on the display.

  3. Enclose the components in a 3D-printed or cardboard case for a portable console!


📽 Bonus: Video Tutorial

$5 for 10 $5 10pcs 1-2 layer PCB Order from PCBWay: https://www.pcbway.com/?from=technology4power


🎥 I'm also making a CapCut Bangla Tutorial Series on this. Stay tuned on my YouTube channel to watch the full build and see it in action!


📎 Conclusion

This project is a fantastic way to learn about Arduino, graphics, and game logic while having fun. Once done, you’ll have your very own handheld Snake Game Console that you built from scratch! 🚀

If you liked this tutorial, leave a comment, share with friends, and subscribe for more awesome DIY electronics projects. ❤️

No comments

Theme images by Bim. Powered by Blogger.