Introduction: Number Puzzle With Arduino

About: My name is José Luis Bejarano Vásquez.Tecnólogo en electrónica, estudiante de ing electrónica, desarrollador de software. Aficionado a la robótica. Blogger.

Hi friends, today want to share this single project. It is about a number puzzle game with arduino, which the game is displayed on the Tv and controlled by a keypad of (4x4)

See video here

For sliding or moving the square of the puzzle, press the key according of the position of the square desired. For example, as shown in the picture, if you want to move the square with the number 5 (which has the fourth position) to the left (because there is a empty position), press the key '4' in the keypad, because it is the fourth position in the keypad.

If you like this project please vote for it in the puzzle contest.


Step 1: List of Components

The materials used for this project are:

  • Arduino One or another model.
  • TV with video output.
  • RCA video cable.
  • (1) 1k ohms resistor.
  • (1) 470 ohms resistor.
  • Hex keypad.
  • Jumpers.

Step 2: Connecting Arduino to the Tv

Download this library and import it to the sketch.

First, add the resistors inline to some hook up wire.

The RCA cable will have 2 wires in it, a ground wire and a video wire.

The 1k ohm resistor is connected to the pin 9 of Arduino.

The 470 ohm is connected to the pin 7 of the Arduino.

Join the ends of the resistors, and connect it to the video cable.

The GND wire of the RCA cabl goes to GND of the Arduino.

If you have problem in the compilation, extract the 3 folders in the library folder.

Step 3: Connect the Keypad

Arduino pinKeyPad
13Row 0
6Row 1
5Row 2
4Row 3
3Col 0
2Col 1
1Col 2
0Col 3

Assemble the project as shown in the picture.

Step 4: The Code

The numbers (1 to 16) are stored in an array.

The number 16 represents the empty position.

For shuffling the numbers, press the key 'A' (at the start of the game), this calls a procedure which shuffles the numbers in the array, and later are shown in the screen.

When you press some key in the keypad, the program verifies if there is some empty position in the near position

(left, right, up or down). As shown in the picture: If the key '1' is pressed, verifies the near positions.


case '1':

change(0,1); //The array(0) position, checks the array(1) position.

change(0,4); // The array(0) position, checks the array(4) position.



The CHANGE function exchange the numbers in the array and the screen it is updated with the numbers.

The game ends when the array it is in the correct order: {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}

Download the full code here.

If you like this project please vote for it in the puzzle contest and in the maker olympics contest


Puzzles Challenge

Participated in the
Puzzles Challenge

Maker Olympics Contest 2016

Participated in the
Maker Olympics Contest 2016