Introduction: Mastermind Star Wars With Arduino MEGA
These are adverse times for rebellion. Although the Death Star has been destroyed, the Imperial troops are using free hardware and Arduino as a secret weapon.
That is the advantage of free technologies, any person (either good or bad) can use them.
In a hidden base located on the planet Anoat, they are building a 3D printer capable of replicating Imperial Destroyer.
The only solution to defeat the Empire is that a group of rebels commanded by Luke Skycuartielles and Obi-Wan Banzi, defeat the imperial troops and get the key that will give access to the plans to destroy the secret weapon.
This key consists of 4 colors and you have 10 attempts to get it deciphered. There are only four rules:
- The colors can be repeated
- A white light indicates that you have hit the right color and position
- A violet light indicates that you have hit the color but not the position
- If there is no light you have not guessed the color or the position.
You must hurry since at the other extreme, the evil Darth Ballmer will try to get the key before you. In that case, you will not be able to find out what it is and you will not have access to the plans of the secret weapon. Your mission will have failed.
Little Padawan, may the force accompany you to decipher the key and thus be able to save the Galaxy.
Step 1: Material
The material needed to make the Mastermind Star Wars with Arduino is divided into three parts.
- Carpentry and stationery for the realization of the housing
- Components, cables and Arduino for all electronics
Let's start with carpentry. The following material is needed:
- 2 x MDF boards from 90x60
- 1 x vegetable paper sheet
In the electronic part, the following material is needed:
- 1 x NeoPixel Strip 5 meters
- 1 x Arduino MEGA
- 1 x capacitor 100 µF
- 4 x resistance 470 Ω
- 5 x black button
- 5 x white button
- 1 x power 5V-5A
- 1 x power 5V-2A
Finally, in the tool part we have used the following:
- Silicone Gun Hot
- Laser CNC de MxN
- Electric welder
- Welder tin
Step 2: Design
One of the most important parts of this project is the design of the housing. It consists of 3 pieces cut with laser cutter.
The base is taken from a 90x60 piece in MDF. Take into account the dimensions of the material since you will need a laser cutter large enough.
You can find the SVG file at the end of this step.
The top cover is the one that contains the thematic drawings of Star Wars as well as the holes for both the buttons and the pixels.
It has the same shape as the base.
The side walls have been made using a laser cutting technique called kerf. This allows the material to be flexible. To place the walls, some pieces have been designed to serve as a guide.
Finally, each NeoPixel matrix has a grid where on one side the NeoPixel are fixed and on the other hand a vegetal paper is fixed to diffuse the light of the NeoPixel. Here you have all the SVG files so that you can cut and manufacture them yourself.
Step 3: Electronic Assembly
The first phase of the assembly of the electronics was to cut the strip of 5 meters of NeoPixel in 8 strips of 10 pixels and 4 separate pixels for each player.
In total 84 pixels per player. On the one hand the 10 strips are assembled one followed by another leaving enough cable to put each strip parallel to a few millimeters. This matrix of pixels will serve to show each play and the result. 4 pixels show the four colors of the key and the other four pixels show the result. I remind you that as a result we have to:
- If the pixel is white, it has been successful position and color.
- If the pixel is violet, the color is correct but not the position.
- If the pixel is off, neither color nor position is correct.
One of the mistakes we have made is the power wiring and GND. It could have been simpler but we realized later. The data cable has to follow an order since the numbering of the pixels goes from bottom to top.
On the other hand we have 4 separate pixels that have to be connected between them. These pixels will show us the color that we are selecting with the buttons.
Connected in series to each strip is a 470Ω resistor to protect the data. The data cable of each strip of pixels is connected to a digital pin. The pins selected in the Arduino MEGA are 6, 7, 8 and 9.
For example, 6 and 7 are for player 1 and 8 and 9 for player 2.
The buttons that we have used are the typical buttons of the arcade machines. We thought they would look good and that's how it was.
Other pushbuttons can be used but it must be taken into account that if they are smaller or larger, the DXF file must be modified before cutting with the laser CNC.
To distinguish the players, some buttons are white and others are black.
Each player has 4 buttons up and 1 button down. The 4 upper buttons serve to select the color of each position of the key.
The bottom button is used to validate, that is, it sends the key to appear in the pixel matrix with the relevant verification of whether the color and position have been successful.
Before assembling everything we soldered all the cables. So you will need a lot of cable. It will depend on the size of the game. In our case it has been quite large.
For example, you can use an ethernet cable to open it and take the internal cables. It's a good solution. Try to have them as orderly as possible because then it will be necessary to make the connections with the Arduino MEGA as you see in the electrical diagram.
Once you are all soldier before mounting it you have to try it. It is tested because when it is installed in the housing, it will be stuck with hot silicone and if it fails it will be complicated then take it off. To place the pixel matrices, a grid has been designed with the same dimensions as the grid of the lid where on one side the pixels are stuck and on the other side a vegetal paper.
This paper diffuses the light of each pixel giving a much more beautiful effect. Then, that structure sticks to the top part inside. It is a bit complicated but with care, a good result is achieved.
The feeding has been somewhat complicated. In principle and looking at the scheme, we were only going to use a single charger. However, after the first tests and the NeoPixel consumption we saw that it would take two chargers.
Each pixel can consume a maximum of 60 mA. If we multiply by 168 pixels, you get a consumption of about 10 A.
Although this would be in the worst case. In the programming we have already taken into account not to maximize the intensity of the NeoPixel.
We do not even reach 50% therefore, with a 5V and 5A charger is more than enough.
On the other hand the Arduino MEGA has a separate charger that can be connected through the jack connector or through the USB port. One possible improvement would be to have a single charger for the entire system.
Step 4: Game Programing
The OneButton library allows to control the buttons in a simple way with interruptions.
The Adafruit_NeoPixel library has allowed us to control the NeoPixel strip in a very simple way.
The programming is based on different states in which the software program can be:
Starting the game. State = 0
In this state, the game is started and there is a sequence of lights in both players indicating that the game is going to start. During this state the pushbuttons do not respond.
Initial state. State = 1
In the initial state, wait for one of the two players to double click on the confirmation button (the fifth button). This action will allow to start the game.
Preparing the game. State = 2
In the state of preparation of the game all the variables are reset and the random selection of colors for the key is launched.
Play State = 3
In state 3 the game starts. Each player selects a key with the buttons and validates it by clicking on the confirmation button. This state can end in two ways: when a player discovers the key or when the two players consume the 10 attempts they have.
One winner State = 4
If a player wins a green check will be shown on his board and the winning combination and a red cross on the loser.
Tied game. State = 5
In the case of a tie, nothing is shown on any board and the winning combination on both players' boards.
Whether there is a winner or a tie in the game, the next state will be the initial one waiting for a double click.
You can find all the code below. The only thing that is in Spanish :)
Step 5: Testing and Improvements
The game is tested by playing. In the video above you can see a complete game.
From here we can think of several improvements that can be added to the Mastermind Star Wars with Arduino.
Next I list them.
- To be able to play in turns with a total of 10 attempts for the two players. When a player tries a key, the other player will see the play.
- An individual game mode so that only one person can play.
- Mode each with its key.
- Include an OLED screen.
- Use a single charger for everything.
- Connect to a NodeMCU ESP8266
I'm sure many people will come up with many improvements. I await the comments below.
And may the force be with you.
Participated in the
Arduino Contest 2019
1 Person Made This Project!
- ricky.philippe made it!