Arduino Sorta Sudoku Game




Introduction: Arduino Sorta Sudoku Game

About: Old dog still learning new tricks.

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.

Step 1: Hardware

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.

Step 2: 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.

Step 3: Displays

Here are some pictures of the various displays.

Battery Powered Contest

Participated in the
Battery Powered Contest

Be the First to Share


    • Make it Glow Contest

      Make it Glow Contest
    • Baking Contest

      Baking Contest
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge