An interactive Sudoku game and solver built for Arduino with a TFT touchscreen display. This project allows you to play, create, and solve Sudoku puzzles using a touch interface.
Note: This project is based on the Electronic Sudoku Game tutorial by TechKiwiGadgets on Instructables.
- Play Mode: Load and play preloaded Sudoku puzzles with varying difficulty levels
- Puzzle Generator: Automatically generate new Sudoku puzzles with configurable difficulty
- Interactive Touch Interface: Use the touchscreen to input numbers directly into the grid
- Help System: Highlight conflicts and errors in red to assist with solving
- Auto Solver: Automated solver that attempts to solve puzzles using multiple algorithms
- Home Mode: Create your own puzzles from scratch or manually enter puzzles to solve
- Arduino Uno R3 (or compatible)
- 2.8" TFT Touch LCD Screen (compatible with MCUFRIEND_kbv library)
- Touchscreen stylus (optional, for better precision)
The following libraries are required and can be installed via the Arduino Library Manager:
MCUFRIEND_kbv- TFT LCD display driverAdafruit_GFX- Graphics core libraryTouchScreen- Touchscreen input handling
-
Install the required libraries using the Arduino IDE Library Manager:
- Go to
Sketch→Include Library→Manage Libraries - Search for and install:
MCUFRIEND_kbvAdafruit_GFXTouchScreen
- Go to
-
Open the main sketch file
sudoku_solver.inoin the Arduino IDE -
Upload the code to your Arduino board
The touchscreen calibration values are defined in sudoku_solver.ino:
#define TS_MINX 934
#define TS_MAXX 149
#define TS_MINY 967
#define TS_MAXY 140If your touchscreen coordinates are incorrect, you may need to adjust these values. The code includes test coordinate data that can be used for calibration.
- Display identifier:
0x9488(ILI9488 controller) - Screen rotation: Portrait mode (can be adjusted in
setup()) - Color definitions can be modified if your display shows incorrect colors
The interface includes four main buttons:
- HOME (Green): Clears the board and allows you to create your own puzzle or manually enter a puzzle to solve
- PLAY (Yellow): Loads a preloaded puzzle or generates a new one. Cycles through 6 different puzzles
- HELP (Magenta): Highlights conflicts in red for half a second to help identify errors
- SOLVE (Blue): Attempts to automatically solve the current puzzle using the solver algorithms
- Press PLAY to load a puzzle
- Touch any cell in the 9x9 grid to select it
- Touch the same cell again to cycle through numbers 1-9 (or 0 to clear)
- Use HELP to check for conflicts if you're unsure about your entries
- Use SOLVE to let the computer solve the puzzle automatically
The system includes a Sudoku puzzle generator that creates valid puzzles with configurable difficulty:
- Easy: 40 digits removed
- Medium: 50 digits removed
- Hard: 60 digits removed
Puzzles are generated using a recursive backtracking algorithm that ensures a valid solution exists.
sudoku_solver/
├── sudoku_solver.ino # Main program file with setup and loop
├── sudoku_game.ino # Game logic, puzzle loading, and solver algorithms
├── sudoku_generator.ino # Sudoku puzzle generator class and functions
├── screen.ino # Display functions (drawing grid, buttons, refresh)
└── touch.ino # Touchscreen input handling and cell value changes
The solver implements several techniques:
- Horizontal Rule: Eliminates possibilities based on solved cells in the same row
- Vertical Rule: Eliminates possibilities based on solved cells in the same column
- Panel Rule: Eliminates possibilities based on solved cells in the same 3x3 box
- Reverse Solve: Identifies cells with only one remaining possibility
- Unique Candidate: Finds cells where a number can only appear in one location within a box/row/column
The Sudoku grid is stored in a 2D array sudoku[82][14] where:
- Index 0: Solve flag (0 = unsolved, 1 = preloaded clue, 2 = solved/entered)
- Index 1: Display value (0-9)
- Index 2: Y coordinate for display
- Index 3: X coordinate for display
- Indices 4-12: Possible values (1-9) for constraint elimination
- Index 13: Panel/box identifier (1-9)
Touch coordinates are mapped to grid positions using a cell-based coordinate system. The touchscreen is debounced to prevent accidental multiple inputs.
- Wrong colors: Check the color definitions in the code (around line 24-32)
- Inverted display: Adjust the rotation in
setup()(line 89) - Touch not working: Recalibrate touch coordinates using the test data in the code
- The solver may not complete all puzzles, especially very difficult ones
- Some puzzles may require manual intervention
- Use the HELP button to identify conflicts before solving
This project is based on the Electronic Sudoku Game tutorial by TechKiwiGadgets on Instructables.
This project is provided as-is for educational and personal use.
Feel free to submit issues, fork the repository, and create pull requests for any improvements.
Enjoy solving Sudoku puzzles!