Skip to content

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.

Notifications You must be signed in to change notification settings

mathvirgilio/Arduino-Sudoku-Solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Arduino Sudoku Solver

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.

Features

  • 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

Hardware Requirements

  • Arduino Uno R3 (or compatible)
  • 2.8" TFT Touch LCD Screen (compatible with MCUFRIEND_kbv library)
  • Touchscreen stylus (optional, for better precision)

Software Requirements

Arduino Libraries

The following libraries are required and can be installed via the Arduino Library Manager:

  • MCUFRIEND_kbv - TFT LCD display driver
  • Adafruit_GFX - Graphics core library
  • TouchScreen - Touchscreen input handling

Installation

  1. Install the required libraries using the Arduino IDE Library Manager:

    • Go to SketchInclude LibraryManage Libraries
    • Search for and install:
      • MCUFRIEND_kbv
      • Adafruit_GFX
      • TouchScreen
  2. Open the main sketch file sudoku_solver.ino in the Arduino IDE

  3. Upload the code to your Arduino board

Configuration

Touchscreen Calibration

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 140

If 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 Settings

  • 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

Usage

Controls

The interface includes four main buttons:

  1. HOME (Green): Clears the board and allows you to create your own puzzle or manually enter a puzzle to solve
  2. PLAY (Yellow): Loads a preloaded puzzle or generates a new one. Cycles through 6 different puzzles
  3. HELP (Magenta): Highlights conflicts in red for half a second to help identify errors
  4. SOLVE (Blue): Attempts to automatically solve the current puzzle using the solver algorithms

Playing the Game

  1. Press PLAY to load a puzzle
  2. Touch any cell in the 9x9 grid to select it
  3. Touch the same cell again to cycle through numbers 1-9 (or 0 to clear)
  4. Use HELP to check for conflicts if you're unsure about your entries
  5. Use SOLVE to let the computer solve the puzzle automatically

Puzzle Generation

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.

Project Structure

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

Solver Algorithms

The solver implements several techniques:

  1. Horizontal Rule: Eliminates possibilities based on solved cells in the same row
  2. Vertical Rule: Eliminates possibilities based on solved cells in the same column
  3. Panel Rule: Eliminates possibilities based on solved cells in the same 3x3 box
  4. Reverse Solve: Identifies cells with only one remaining possibility
  5. Unique Candidate: Finds cells where a number can only appear in one location within a box/row/column

Technical Details

Data Structure

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 Input

Touch coordinates are mapped to grid positions using a cell-based coordinate system. The touchscreen is debounced to prevent accidental multiple inputs.

Troubleshooting

Display Issues

  • 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

Solver Issues

  • 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

Credits

This project is based on the Electronic Sudoku Game tutorial by TechKiwiGadgets on Instructables.

License

This project is provided as-is for educational and personal use.

Contributing

Feel free to submit issues, fork the repository, and create pull requests for any improvements.


Enjoy solving Sudoku puzzles!

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published