Features โข Hardware โข Installation โข Usage โข Configuration โข Troubleshooting
A faithful recreation of the classic Nokia Snake game for Arduino microcontrollers. This project combines retro gaming nostalgia with modern embedded programming practices, featuring smooth OLED graphics, responsive controls, persistent high scores, and progressively challenging gameplay.
- ๐ฎ Classic Snake Gameplay - Faithful recreation of the Nokia original
- ๐ Persistent High Scores - Saved to EEPROM, survives power cycles
- ๐ Win Condition - Reach maximum length (150 segments) to win!
- ๐ Progressive Difficulty - Game speeds up every 5 points
- ๐ฏ Smart Collision Detection - Wall, self-collision, and food detection
- ๐พ Ultra Memory Efficient - PROGMEM optimization frees up RAM
- ๐ฅ๏ธ Flicker-Free Display - Full buffer rendering for smooth 24 FPS graphics
- ๐น๏ธ Responsive Controls - Input debouncing and anti-reverse logic
- ๐ Instant Restart - Press any button to play again
- ๐ Real-time Stats - Current score and high score displayed while playing
- โญ High Score Celebration - Special message when you beat your record
- ๐ง High Score Reset - Dedicated button to clear records
- โก Full buffer mode - Switched to
U8G2_Ffor completely flicker-free rendering - ๐ง PROGMEM strings - All text moved to flash memory, saving precious RAM
- ๐ฏ Frame-rate control - Fixed 42ms draw intervals (24 FPS) for consistent visuals
- ๐พ Input debouncing - 50ms debounce prevents accidental double-inputs
- ๐ EEPROM high scores - Your best score is saved permanently
- ๐ Win screen - Special celebration for reaching max length
- ๐ Reset button - Pin 4 clears high scores
- โญ New record indicator - Get notified when you beat your best
- ๐ Increased max length - Now 150 segments (up from 100)
- โ๏ธ Better difficulty curve - Speed increases every 5 points (was 3)
- ๐ฎ Refined starting speed - 500ms starting speed for better balance
- ๐ฏ Optimized grid - 6x6 pixel cells for smoother gameplay (was 4x4)
| Component | Specification | Quantity |
|---|---|---|
| Arduino Board | Uno/Nano (ATmega328P) | 1 |
| OLED Display | SH1106 128x64 (I2C) | 1 |
| Push Buttons | Momentary tactile switches | 5 |
| Breadboard | Standard size | 1 |
| Jumper Wires | Male-to-male | ~12 |
Estimated Cost: $12-15 USD
โโโโโโโโโโโโโโโโโโโ
โ OLED Display โ
โ (SH1106 I2C) โ
โโโโโโโโโโโโโโโโโโโ
โ โ โ โ
SDA SCL VCC GND
โ โ โ โ
A4 A5 5V GND โ Arduino
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Push Buttons โ
โโโโโโโโโโโโโโโโโโโโโโโโค
โ UP โ Pin 6 โ
โ LEFT โ Pin 7 โ
โ DOWN โ Pin 9 โ
โ RIGHT โ Pin 10 โ
โ RESET โ Pin 4 โ โ NEW!
โ (All buttons โ GND) โ
โโโโโโโโโโโโโโโโโโโโโโโโ
- U8g2lib - High-performance OLED display driver
- Installation: Arduino IDE โ Tools โ Manage Libraries โ Search "U8g2" โ Install
- Version: Latest stable (tested with v2.35+)
- Author: olikraus
- EEPROM - Built-in Arduino library (no installation needed)
Choose your preferred installation method:
-
Download the Latest Release
- Go to Releases
- Download the latest
snake_arduino_v1.1.inofile - Save it to a folder named
snake_arduino_v1.1
-
Install U8g2 Library
- Open Arduino IDE
- Navigate to
ToolsโManage Libraries - Search for "U8g2" by oliver
- Click
Install - Restart Arduino IDE
-
Hardware Setup
- Connect OLED display to I2C pins (A4/SDA, A5/SCL)
- Wire push buttons to pins 4, 6, 7, 9, and 10
- Connect 5V and GND to all components
-
Upload Code
- Open
snake_arduino_v1.1.inoin Arduino IDE - Select your board:
ToolsโBoardโArduino Uno/Nano - Select your port:
ToolsโPortโ (your Arduino port) - Click Upload (Ctrl+U / โ+U)
- Open
-
Play!
- Game starts automatically after upload
- Use directional buttons to control the snake
- Eat food to grow and increase score
- Beat your high score!
-
Clone the Repository
git clone https://github.com/aydakikio/arduino_snake.git cd arduino_snake -
Install U8g2 Library (same as Method 1, step 2)
-
Follow steps 3-5 from Method 1
Note: Arduino IDE requires
.inofiles to be in a folder with the same name
| Button | Action |
|---|---|
| UP | Move snake upward |
| DOWN | Move snake downward |
| LEFT | Move snake left |
| RIGHT | Move snake right |
| RESET | Reset high score (during gameplay) |
| ANY (Game Over) | Restart game |
- Objective: Eat food (small squares) to grow your snake and increase score
- Speed: Game gets faster every 5 points (500ms โ 100ms minimum)
- High Score: Your best score is automatically saved and displayed
- Win Condition: Reach 150 segments to win the game!
- Game Over: Hitting walls or yourself ends the game
- Scoring: +1 point per food eaten
- No Reverse: Can't make 180ยฐ turns (prevents accidental death)
- Automatic Save: High scores are saved immediately when achieved
- Persistent Storage: Scores survive power cycles and resets
- Reset Option: Hold the RESET button (pin 4) to clear high scores
- New Record Alert: See "NEW HIGH SCORE!" message on game over screen
Customize game behavior in the source code:
// Game difficulty settings
#define SNAKE_MAX 150 // Maximum snake size (win condition)
#define GRID_SIZE 6 // Pixel size of grid cells
int game_speed = 500; // Starting speed (ms per move)
int min_speed = 100; // Minimum speed cap
// Speed progression (in main loop)
if (score % 5 == 0 && game_speed > min_speed) {
game_speed -= 15; // Speed increase per milestone
}#define INPUT_DEBOUNCE 50 // Button debounce time (ms)
#define DRAW_INTERVAL 42 // Frame time (ms) - ~24 FPSChange Button Pins:
#define BTN_RIGHT 10 // Modify these to match your wiring
#define BTN_DOWN 9
#define BTN_LEFT 7
#define BTN_UP 6
#define BTN_RESET 4 // High score reset buttonSwitch Display Controller:
// For SSD1306 displays, replace line 3 with:
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);Adjust EEPROM Addresses:
#define EEPROM_HIGH_SCORE_ADDR 0 // High score storage address
#define EEPROM_MAGIC_ADDR 2 // Validation byte address
#define EEPROM_MAGIC_VALUE 42 // Validation valueโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Main Game Loop โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 1. Handle Input (debounced) โ
โ 2. Update Game State (timing) โ
โ 3. Move Snake (grid-based) โ
โ 4. Check Collisions (walls/self) โ
โ 5. Process Food (growth/spawn) โ
โ 6. Update High Score (EEPROM) โ
โ 7. Render Display (full buffer) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Data Structures:
struct Point {
int8_t x, y; // Grid-aligned coordinates (optimized)
};
Point snake[SNAKE_MAX]; // Snake body segments (150 max)
Point food; // Food positionCore Systems:
- Display: U8G2 full-buffer rendering for flicker-free graphics
- Input: Debounced button reading with direction validation
- Timing: Non-blocking
millis()based updates with frame limiting - Physics: Grid-snapped movement with precise collision detection
- Storage: EEPROM persistence with magic byte validation
- Memory: PROGMEM strings to minimize RAM usage
| Metric | Value | Change from v1.0 |
|---|---|---|
| RAM Usage | ~950 bytes | +150 bytes (buffer) |
| Flash Usage | ~16KB | +1KB (features) |
| Frame Rate | 24 FPS (capped) | Fixed timing |
| Input Latency | <50ms | Improved |
| Max Snake Length | 150 segments | +50% |
| Display Buffer | Full (1024 bytes) | Upgraded |
Problem: OLED screen stays blank
- โ Verify I2C connections (SDAโA4, SCLโA5)
- โ Check power connections (VCCโ5V, GNDโGND)
- โ Confirm display controller type (SH1106 vs SSD1306)
- โ Test I2C scanner sketch to verify address
- โ Try swapping SDA/SCL wires
- โ Ensure U8g2 library is installed correctly
Problem: Display flickers or artifacts
- โ
Verify you're using
_F_buffer mode (full buffer) - โ Check power supply stability (use quality USB cable)
- โ Add 100ยตF capacitor across display power pins
Problem: Display is rotated/mirrored
- Change
U8G2_R0toU8G2_R1,U8G2_R2, orU8G2_R3in line 3
Problem: Buttons not responding
- โ Verify correct pin numbers in code match hardware
- โ Check button wiring (should connect pin to GND)
- โ Test with multimeter or LED to confirm button function
- โ Ensure INPUT_PULLUP is enabled in code
Problem: Snake moves on its own or erratically
- Check for loose button connections
- Verify no short circuits between button pins
- Increase
INPUT_DEBOUNCEvalue to 100ms - Add 0.1ยตF capacitors across buttons
Problem: Reset button doesn't clear high score
- Hold button for 1+ second
- Check pin 4 connection
- Verify delay(500) in reset code executed
Problem: High score doesn't save
- โ Verify EEPROM_MAGIC_VALUE is being written
- โ
Check that
saveHighScore()is called after new records - โ Ensure Arduino has EEPROM support (Uno/Nano do)
- โ Try clearing EEPROM with example sketch first
Problem: High score corrupted or wrong value
- Call
resetHighScore()manually - Check EEPROM addresses don't conflict with other projects
- Verify
EEPROM.get()andEEPROM.put()used correctly
Problem: Can't reset high score
- Hold RESET button (pin 4) during gameplay
- Verify button is wired to pin 4 and GND
- Check
digitalRead(BTN_RESET)returns LOW when pressed
Problem: Food spawns inside snake
- This is prevented by algorithm, but if occurring:
- Check
generateFood()validation loop - Verify
snake_lengthis tracked correctly - Ensure random seed initialized in
setup()
Problem: Game runs too slow/fast
- Adjust
game_speedvariable (higher = slower) - Check
DRAW_INTERVALisn't too long - Verify
millis()timing isn't blocked
Problem: Can't reach win condition
- Check
SNAKE_MAXdefinition (should be 150) - Verify win condition in main loop:
if (snake_length >= SNAKE_MAX) - Ensure food continues spawning until max length
Problem: Arduino resets randomly or behaves erratically
- โ
RAM overflow - reduce
SNAKE_MAXif needed - โ Stack overflow - check for infinite recursion
- โ Use PROGMEM for all constant strings
- โ
Monitor RAM usage with
freeMemory()function
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Add sound effects with piezo buzzer
- Implement different difficulty modes
- Add two-player mode
- Create custom food types with bonuses
- Add obstacles or maze levels
- Port to other display types
Please ensure code follows existing style and includes comments.
- โจ Added persistent high score storage (EEPROM)
- โจ Added win condition (max length 150)
- โจ Added high score reset button
- โก Upgraded to full buffer mode for flicker-free display
- ๐ง Optimized memory with PROGMEM strings
- ๐ฏ Improved frame-rate control (fixed 24 FPS)
- ๐ฎ Better input debouncing (50ms)
- ๐ Adjusted difficulty curve (every 5 points)
- ๐ง Increased grid size to 6x6 pixels
- ๐ Fixed Serial debug code leftover
- ๐ฎ Initial release
- Basic snake gameplay
- Progressive difficulty
- Collision detection
- Score tracking
This project is licensed under the MIT License - see the LICENSE file for details.
You are free to use, modify, and distribute this code for personal and commercial projects.
- U8g2 Library by olikraus - Excellent OLED driver
- Nokia - For the original Snake game inspiration
- Arduino Community - For extensive documentation and support
- Contributors - Thank you to everyone who suggested improvements!
- Issues: Found a bug? Open an issue
- Discussions: Have questions? Start a discussion

