Arduino Sorta Sudoku Game
![Sudoku Display4.jpg](/proxy/?url=https://content.instructables.com/FOX/X0V5/KH1ZFZJK/FOXX0V5KH1ZFZJK.jpg&filename=Sudoku Display4.jpg)
A lot of people like to play Sudoku and the grandkids like guessing games so I decided to make a portable “Sorta Sudoku” game. In my version the game is a 4x4 grid but only one number is provided. The idea is to guess the rest of the numbers in the fewest tries. It’s a simple game but it can be kind of addicting as you pursue the perfect score of 15. The game requires both an element of luck as well as logic and the best score I’ve seen so far is 16. Take a look because even if you aren’t interested in building the game, there might be some elements of the software that you can use in one of your own projects.
Hardware
![Arduino Sudoku Game.jpg](/proxy/?url=https://content.instructables.com/FH2/DU4J/KH1ZFZD6/FH2DU4JKH1ZFZD6.jpg&filename=Arduino Sudoku Game.jpg)
![Battery Board.jpg](/proxy/?url=https://content.instructables.com/FJH/WT3C/KH1ZFZD7/FJHWT3CKH1ZFZD7.jpg&filename=Battery Board.jpg)
![Boost Board.jpg](/proxy/?url=https://content.instructables.com/FVT/XQ34/KH1ZFZD8/FVTXQ34KH1ZFZD8.jpg&filename=Boost Board.jpg)
![Sudoku Box.jpg](/proxy/?url=https://content.instructables.com/FR0/PZSF/KH1ZFZDA/FR0PZSFKH1ZFZDA.jpg&filename=Sudoku Box.jpg)
![Sudoku Battery.jpg](/proxy/?url=https://content.instructables.com/F7F/EQVD/KH1ZFZD9/F7FEQVDKH1ZFZD9.jpg&filename=Sudoku Battery.jpg)
![Sudoku Electronics.jpg](/proxy/?url=https://content.instructables.com/FOI/Y9XF/KH1ZFZDF/FOIY9XFKH1ZFZDF.jpg&filename=Sudoku Electronics.jpg)
The hardware can be based on pretty much any Arduino version. I did the prototyping using a Nano and then burned the code into an ATMega328 chip. That is the same chip used in the Nano but using it by itself allows for a more compact build and less power consumption. As you can see, I built the circuit on a small breadboard that piggybacks on the LCD module. The other aspect that is different is that the Nano runs at 16-MHz using an external crystal but I chose to use the built-in 8-MHz oscillator for the ATMega328 chip. That saves parts and power.
The 2004 LCD interfaces to the Arduino the same way as a 1602 LCD. An interesting difference is in the addressing of the display locations. Obviously there is a difference because there are four lines instead of two but, in the 2004, the third line is an extension of the first line and the fourth line is an extension of the second line. In other words, if you had a test program that just sent out a string of characters to the LCD, the 21st character would show up at the start of the third line and the 41st character wraps back around to the start of the first line. The software handles that difference with an LCD address lookup table.
The input for the game is a homemade 4x4 switch matrix. Each switch corresponds directly to the equivalent location on the display. There is also a power switch and a reset switch. The reset switch clears the old game and generates a new game.
I decided to make my version battery powered so I used a common 18650 Li-ion, 3.6-volt battery. That required that I add a small board to allow for USB recharging and another small board to boost the battery voltage to 5 volts for the LCD and the ATMega chip. The pictures show the modules I used but there are also all-in-one modules that do both functions.
Software
The software is the same for both the Nano and the ATMega328 chip. The only difference is in the programming method. I use my own barebones version of LCD software and keyboard matrix decode software. These are separate “include” files for the project.
The commands “random” and “randomSeed” are used to help create the game. I added a save to EEPROM of the “seed” to ensure that a different sequence is generated at each powerup. The lines for the puzzle are derived from a 24-element lookup array. The first three lines are randomly selected from the table, with checks to make sure that a selected line doesn’t conflict with a previous line. The last line is manually filled because there will only be one possible pattern at that point. After that it’s just a matter of scanning the keyboard matrix and converting the key presses to numbers.
To guess a number, press the corresponding switch repeatedly. Each press increases the displayed number. If you overshoot the number you want, just keep pressing. If you release the switch for a second, it will lock in the last number displayed. If the number is incorrect it will clear the number and you can try again. Each guess increments the displayed counter and once a number is correctly guessed, that matrix switch is effectively disabled.
Displays
![Sudoku Display1.jpg](/proxy/?url=https://content.instructables.com/FSD/UPFT/KH1ZFZJG/FSDUPFTKH1ZFZJG.jpg&filename=Sudoku Display1.jpg)
![Sudoku Display2.jpg](/proxy/?url=https://content.instructables.com/F7E/Q9RH/KH1ZFZJH/F7EQ9RHKH1ZFZJH.jpg&filename=Sudoku Display2.jpg)
![Sudoku Display3.jpg](/proxy/?url=https://content.instructables.com/F1T/2Q1L/KH1ZFZJI/F1T2Q1LKH1ZFZJI.jpg&filename=Sudoku Display3.jpg)
Here are some pictures of the various displays.