BattleShip Game in Arduino R4 Minima

by Daniel Larrubia Gil in Circuits > Arduino

95 Views, 4 Favorites, 0 Comments

BattleShip Game in Arduino R4 Minima

IMG-20250121-WA0019.jpg

This project is based on the creation of the well-known board game Battleship, also known as “Hundir la flota” in Spain.

This game is characterized by being very dynamic and fun to play for two people in matches lasting approximately 10 minutes.

The idea has been developed by the following University of Málaga students: Daniel Larrubia Gil, Bernardo Francisco Suárez Herrera and Nicolás Vidales Moezzi.

All the steps we took in order to create this project are going to be explained in the following chapters:

Supplies

  1. (x2) Power source of 10A
  2. (x4) 16x16 Adafruit LED matrix panel
  3. Arduino UNO R4 minima.
  4. (x2) Nintendo NES controllers
  5. Diffuser plate for LEDs
  6. PLA filament for 3D printer
  7. Wires and a socket for the power supply
  8. Fan to refresh the power source
  9. Tin to solder the wires
  10. (x50) m2 screws and nuts
  11. Speaker for the interactive sound
  12. DF Player and an USB for the storage of sound effects and one 1kΩ resistor

HARDWARE DESIGN

diseño1.png
diseño2.png
diseño3.png

We decided to make an original design by modeling the whole case in Tinkercad step by step. The idea was to model the typical paper boat, having the same things in each side.

Each player will have two screens: one on the top of the boat, just to watch the target map and to select where to attack, and the other one on the bottom, to see what the enemy is doing on your map.

On the front side, there will be some indicators in order to make the game easier by lighting whose current turn it is and who won the match at the final of the game.

Anyways, the 3D printing models are attached in this file to skip this step.

SOFTWARE DESIGN

The program we have made for the video game runs in Arduino IDE, which uses the C++ programming language. We control the buttons for each controller and manage the high-level behavior of the ships.

Getting deeper in the ships behaviour, we created the following files:

The software program consists of 3 main files:

- BattleShip.ino, which contains the main program, including the implementation of the texts, images, sound effects and 2vs2 functionality.

- BattleShip.cpp, which contains the functions that can be done to each ship.

- BattleShip.hpp, which includes the structure of the Battleship class with its respective encapsulated attributes.

- TextoInicio.h, which contains the image of the game title in RGB code.


In order to implement the program, several libraries are needed:

- arduino.h

- Adafruit_GFX.h

- Adafruit_NeoMatrix.h

- Adafruit_NeoPixel.h

- DFRobotDFPlayerMini.h


The BattleShip.ino file implements the state machine needed for the game, the states being: start, placement, attack (turns J1 and J2) and end.

In each of the states different actions are performed. In the first state a menu of options is shown that allows to modify the volume (with the button B) and the Brightness (with the button A), and there is also a button to start the game (play).

In the second state the game starts as such, where the ships are placed. These ships can be placed side by side and rotated using the B button, and 5 types of ships are available on a 16x16 board: barque, cruiser, long ship, submarine and aircraft carrier.

To pass to the next state of the game, both players must finish the ship placement.

Once passed to the third state, the attack on the enemy ships begins.

The first player must select a square to attack with the joystick and press the A button to confirm it. If he has hit the square, it will light up green on the screen above, and the damaged ship's square will turn yellow.

In case of failing in the attack, the led of the attack screen will be blue. It will remain in this state until all the ships have been knocked down.

In the last state, the game title screen will be displayed and a “winner” sign for the winner's monitor and a “looser” sign for the loser's monitor. The machine will remain on standby until one of the two players reloads the program in case they want to start another game.

ASSEMBLY

IMG-20250121-WA0030.jpg
IMG-20250121-WA0031.jpg
IMG-20250121-WA0032.jpg
montaje1.png
montaje2.png
DFplayer mini.png
MontajeDFPlayer.png

The last step is to place every part of the Battleship’s game in order to make this run.

First, we have to connect the controllers into the Arduino board like this:

After printing all the boat case and gluing all the pieces together, we have to place the LEDs panels in each grid from the inside. Then, we will place the power sources and the Arduino board in the bottom of the boat and connect it all with wires.

In addition, the DF Player has to be connected to the Arduino like in the image.

Anyways, all the instructions in order to installate the sound files is in the annex.

Finally, we can enjoy one of the best 1 vs 1 board games!

ANNEX

  1. GitHub repository in which you can download all the project:

Dan1LG/BattleShipGame: BattleSHip game in Arduino UNO R4 Minima


  1. Web that converts images into RGB code for the title:

Convert PNG to RGB Values – Online PNG Maker

  1. Project that we used as a reference to make the texts of the screens:

https://www.instructables.com/Color-Scrolling-LED-Text-and-Images-With-Arduino/


  1. Video for DF Player installation:

Como REPRODUCIR MÚSICA O AUDIO CON ARDUINO Y CONECTAR A UN AMPLIFICADOR CON ALTA CALIDAD (DFPLAYER)


  1. Detailed page of the creator of the DF Player video:

Modulo DFplayer mini Reproductor mp3 para arduino, tutorial completo