Alien Shooter Game With Arduino and LCD
by Abdur-raheem in Circuits > Arduino
33 Views, 0 Favorites, 0 Comments
Alien Shooter Game With Arduino and LCD
Everyone loves going to the arcade. However there is only one problem to that. You have to go to the arcade and then pay to play games. So I came up with the perfect solution.
Make a game myself so I can play for FREE and WHENEVER I want to.
And now I am sharing this project with you so that you too can have your own personal little arcade game.
Supplies
If you also want to build an Alien Shooter Game for yourself you will need the following supplies:
All the required materials are linked to the place you can order them or get them
- 16x2 LCD with I2C module
- Pushbuttons x5
- 10kΩ resistors x5
- LED(any color)
- Buzzer
- 330Ω resistors
- Wires(circuit is color coded)
- Male to Female Wires x4
- Wire Strippers or Wire Cutters
- Breadboard
- Arduino Uno
- Cable to connect Arduino to device
- Arduino IDE installed on a device
- Liquid Crystal I2C library(may need to download)
- Wire Library(come pre installed in Arduino IDE)
Now that you have everything you need we can get building!!
Schematic
Here is the schematic of the circuit you can refer back to this if any of the steps are confusing or don't make sense since this schematic shows you exactly where everything goes and how it should be connected.
You can also just ignore the steps and make the circuit based of this if you want to.
Note: Lines that cross each other are not connected unless their is a filled in circle where they cross.
Components for Controls
What you'll need for this step:
- Pushbuttons x5
- 10kΩ resistors x5
- Red Jumper Wires x5(I am using red since it is for power and red is standard for power, you can use any color if you don't have red)
First let's get the push buttons wired up.
Put the Pushbuttons onto the Breadboard across the two sections as shown in the picture above. Group four of them together leaving enough space between them so that they could easily be pressed individually, these will be the buttons for movement. Put the last and fifth button separate from the rest of the buttons and again put it across the two sections of the breadboard. The setup I described as well as showed makes it easier for me to show you how to build the circuit since now you can just copy what I have and not have to worry about your pushbutton being in the wrong orientation since pushbuttons only fit in one orientation across the two halves of the breadboard.
After you have placed all the pushbuttons you have to begin placing the resistors. Place the resistor so that it serves as the bridge connecting one leg of the pushbutton to the ground rail on the breadboard and then on the side of the pushbutton and breadboard that you connected the resistor to using the other leg(each pushbutton will have two legs on either side of the breadboard) connect it to power using a small red jumper wire as the bridge. Then repeat this process for each of the pushbuttons.
Note: Trimming resistor so that they fit will help to make the circuit look cleaner and easier to debug later
Optional at this point:
You can label what each push button is for now but this is not needed and can be done at the end. If you don't label remember the shoot button is the one button that is alone and the movement controls are grouped together.
Component for Sounds and Effects
What you'll need for this step:
- Buzzer
- LED(your choice of color)
- 330Ω resistors
- Small Black Wire(I am using black since it is for power and black is standard for ground, you can use any color if you don't have black)
Now that you have the pushbuttons wired up it's time to get the rest of the components wired up as well.
Put the buzzer to the left of the pushbuttons on the top half of the breadboard(as shown above). Then take the small black wire and place it so that it serves as a bridge connecting the ground pin on the buzzer(there should be a plus indicating which pin is for power) to the ground rail on the breadboard.
Put the led on the right of the button for shooting(the button that is alone). Then take the 330Ω resistor and place it so that it serves as a bridge connecting the cathode or ground pin of the led to the ground rail on the breadboard. To differentiate between the anode and cathode of the led look at the legs. The longer leg indicated the anode and the shorter one is cathode. However if the legs are the same size you can look at the led head and there should be two metal looking pieces that are different sizes inside. The smaller piece of is the anode and the bigger is the cathode. For reference refer to the image above.
Connecting the LCD I2C
What you'll need for this step:
- 16x2 LCD with I2C module
- Male to Female Wires x4
Now it's time to get the LCD I2C wired up.
The I2C module had 4 pins which are: ground, power, SDA(Serial-Data Line), and SCL(Serial-Clock Line). I used four different colors for each(as you can see in the picture above. Blue is for ground, Pink is for power, Orange is for SDA, and Yellow is for SCL(for the ground and power pins it is better to use red for power and black for ground in order to stay consistent but I did not have those colors so I improvised)
Connect the ground and power pins to the ground and power rails of the breadboard(ground to ground, power to power) and the SDA pin has to be connected to A4 on the Arduino and the SCL pin has to be connected to A5. This is because A4 and A5 are dedicated I2C communication pins and this is because of how the board is built and the microcontroller.
Connecting Everything to the Arduino
What you'll need for this step:
- 4 different colored wires so that you can color code the circuit and make it easier to read( I used purple, yellow, green and orange but the color does not matter)
- Red Wires(I am using red since it is for power and red is standard for power, you can use any color if you don't have red)
- Black Wires(I am using black since it is for power and black is standard for ground, you can use any color if you don't have black)
Now it is time to connect everything to the Arduino.
The best way to do this is to put the Arduino next to the breadboard so that the side with all the pins is closest to the breadboards(as shown above).
I will be referencing the colors I used(purple, green, orange, and yellow) but you can use whatever color you want in it's place since I am just using these colors to color code the wiring to make it neater and nicer to look at.
Using your first color(purple) connect the power pin on the buzzer to pin 2 on the Arduino.
Then using your second color(green) connect the pushbuttons meant for movement to pins 3, 4, 5, and 6. To connect the push buttons all you have to do is put a wire going from the desired pin on the Arduino to the leg of the pushbutton directly across from the leg connected to ground with the resistor.
Now connect the last pushbutton using your third color(orange), the one for shooting, to pin 7 using the same method you used to connect the pushbuttons for movement just before this.
Lastly connect the LED of your chosen color(in my case yellow) to the Arduino using your fourth chosen color(yellow) by connecting the anode of the led to the Arduino pin 9.
Also make sure you connect the 5v power supply and ground from the Arduino to the corresponding rails on the breadboard using a red wire for power and a black wire for ground. Also keep in mind there are two power rails and two ground rails on each side of the breadboard and we used both sides for this project so to make sure all sides get power get two wires one red for power and one black for ground and connect the power rail to the power rail and the ground rail to the ground rail. This way you don't have to worry about which side you are using to give power or ground since both rails for power and both rails for ground are connected.
Coding
Now that you are done all the wiring it is time to get coding.
First off you will need two libraries the Liquid Crystal I2C library and the Wire library.
To access these libraries open up your Arduino IDE sketch(if you do not have the IDE downloaded then download it here) and then in the top left corner in the menu select Sketch then a drop down menu will appear and from there select "Include Library" then search in the installed libraries for either the Wire or Liquid Crystal I2C library and if you find it click on it and it will auto include in your sketch. If the library is not there you will need to download it. The Wire library comes pre installed while the Liquid Crystal I2C library will need to be downloaded.
You can find the library in the following link:
Download the file below to access the code. But make sure you have the Liquid Crystal I2C downloaded or it won't work. After you download the file and open it in the Arduino IDE all you have to do is upload it to the Arduino and get ready to play your game.
Note: Before uploading check to see if all the pins are correct and match up with the code.
The code is commented and explained in the file.
After you are done with the code and have uploaded it you should label which buttons do what. As in what is their function(up, left, down etc.). In the code you would have assigned these functions to the buttons connected to the Arduino pins so to figure out which button does what just check the pin initialization in the code.(I