Snake Game With Arduino
Intro: Snake Game With Arduino
This instructable shows you how to build a portable snake game device.
You can play the game on a 8x32 LED matrix, and control it with the help of a joystick. There are two bonus LEDs, which are some power ups, double points or you can go through walls.
You can play on different difficulties.
I'm planning to make other games too, which can be played with the Joystick and the Potentiometer.
I won't go into the details about the programming, if you are interested in it ask me about that. If you have any other questions about the project I'm happy to help.
STEP 1: Collect Everything
Things you need:
- Arduino Uno + Power cable
- Breadboard
- 8*32 led matrix (MAX7219 Dot Matrix Module, 4 In One Display with 5P Line)
- 4Bit led (SM420561k-32)
- 10kΩ potentiometer
- 2 x 220Ω Resistor
- Joystick module (KY-023 XY-axis joystick module)
- Green led
- Blue led
- A bunch of jumper wires
-Download the snake.ino sketch
To make the box, and the fix the parts (you can do the project without these, simply fixing everything on a single panel)
- 4x 15cm *12.5cm wooden panel
- 2x 12.5cm * 12.5cm wooden panel
- Hot glue
- Drill
- Jigsaw
Libraries you need to be installed:
Important: You might need to edit the MAX72xx.h file to set the type of matrix you are using.
STEP 2: Prepare the Box
Cut one of the 15x12.5cm and one of the 12.5x12.5cm wooden panels as shown on the pictures. The 15x12.5 panel is going to be the top panel, and the 12.5x12.5 be the left panel.
Glue the parts together as shown. Place the 15x12.5 rectangle on the button. Glue two other rectangles on their longer sides. The square panels are going to the left and right sides. Do not glue the top part yet.
STEP 3: Connecting the LED Matrix Display
First of all, connect the Arduino 5V to the + on the Breadboard, and the Gnd to the -
Upload the sketch to the Arduino, then plug out the USB cable.
The led display has 5 pins, connect them like:
- VCC to +
- GND to -
- DIN to Arduino D11
- CS to Arduino D10
- CLK to Arduino D13
Plug in the USB, if you see characters on the display, it works fine.
STEP 4: Connect the 4bit Led Display
Place the display above the 2x2cm hole, and glue it. Than connect the jumper wires to the pins.
Pins on the display are from 1-12. 1-6 is on the top from left to the right. 7-12 is on the bottom also from left to the right.
- 1 to Arduino D5
- 2 to Arduino D6
- 3 to Arduino D7
- 4 to Arduino D8
- 5 to Arduino D9
- 6 to Arduino D19/SCL Pin
- 7 to Arduino D0
- 8 to Arduino D1
- 9 is not in use now, because we don't need the dot.
- 10 to Arduino D2
- 11 to Arduino D3
- 12 to Arduino D4
Plug in the USB cable, if you see 0000 on the display, it's fine.
STEP 5: Connect the Joystick
- GND to -
- 5V to +
- VRx to A0
- VRy to A1
- SW to A2
You don't have to stick it yet.
STEP 6: Connect the Potentiometer
Connect the potentiometer as shown on the picture. Then fix it with hot glue as shown. Then place the helmet on the potentiometer and check it whether you can rotate it properly.
STEP 7: Glue the LEDs
Place the LED through the hole, stick it there with hot glue. Connect the jumper wires to the LED leads, stick them with hot glue for a better connection.
STEP 8: Finish the Box
Glue the top to the box, be careful with the jump wires. Than glue the LED matrix to the middle and the Joystick to the bottom right side. Lead the jumper wires throuht the gaps between the panels.
Connect the power cable to the Arduino on the bottom, and upload the given code.
STEP 9: How to Play
POINTS: It shows your last score
REC: It shows your best score
DIFF: You can set the difficulty here with the potentiometer
You can change the screens with the joystick, by pulling it left or right.
How to play
- Control the snake with the joystick. Up, down, left or right but pay attention because you can turn back and die instantly. (For example if you are going up and the you pull down the joystick..)
- Hold the joystick in the direction you are about to go.
- When the green light turns on you can go through walls
- When the blue light turns on you get double points
- You can get those power-ups when you pick up a point
Difficulties are from 0-10.
- Higher difficulty means faster starting speed
- And you get less frequently power-ups
Have fun!
23 Comments
Noodle_ 3 years ago
Noodle_ 3 years ago
In a previous comment a user named, Mister N, had issues with their 8x32 LED matrix display, and luckily another user named, Mataksik, was kind enough to offer a fix, which has also fixed my issue. Thanks a bunch Mataksik!
//Add
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW// PAROLA_HW
//Edit
#define MAX_DEVICES 4
//Add
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
Avion44 2 years ago
Also, the parts are so expensive. Buying the parts I didn't have costed $40. So failing this project would feel real sad. Thanks again for this update!!
AliK287 4 years ago
Noodle_ 3 years ago
KURUK1 4 years ago
-fpermissive ] MD_MAX72XX mx = MD_MAX72XX (CS_PIN, MAX_DEVICES);
^
C: \ Users \ USER \ AppData \ LocalLow \ Empyrean \ House Flipper Oyunu \ Crashes \ Crash_2018-06-02_182540 \ Downloads \ snake \ snake.ino: 2: 0:
C: \ Users \ USER \ Documents içinde bulunan dosyada \ çaba isteyen \ kütüphaneleri \ MD_MAX72XX-ana \ src / MD_MAX72xx.h: 377: 3: Not: 'MD_MAX72XX :: MD_MAX72XX (MD_MAX72XX :: moduleType_t, uint8_t, uint8_t) n' in bağımsız değişkeni 1 başlatılıyor
csPin uint8_t MD_MAX72XX (moduleType_t mod, uint8_t numDevices = 1);
^ ~~~~~~~~~
şeklinde bi hata veriyo nasıl çözebilirim
powercellar 4 years ago
Mister N 6 years ago
Hello I'm trying to do that very nice little game for my electronixclass, but Iam having a problem and hope that some one could help me pls.
Every thing is right conectet and it is with "point", "rec", "diff" and while the game like this
mataksik 4 years ago
//add
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW// PAROLA_HW
edit
#define MAX_DEVICES 4
#define CLK_PIN 13 // or SCK
#define DATA_PIN 11 // or MOSI
#define CS_PIN 10 // or SS
//add
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
tastyy 5 years ago
Hey,
you have to use an older version of the MD_MAX72xx library. Use the 2.10.0 vers. and it works fine!
Osafter 5 years ago
hey, i had the same problem, and i did what you say, but the problem is not gone
Osafter 5 years ago
Hello , i have same Problem as Mister N, could you help me pls, and when i play the game the directions of the joystick are switcht, i hope you answer me an help, PS. Could you tell , how the LED´s are connectet , thanks
mataksik 4 years ago
//add
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW// PAROLA_HW
edit
#define MAX_DEVICES 4
#define CLK_PIN 13 // or SCK
#define DATA_PIN 11 // or MOSI
#define CS_PIN 10 // or SS
//add
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
AnnaB222 4 years ago
AnnaB222 4 years ago
JEF5 5 years ago
hi! I'm having a problem with my dot matrix, I really hope that you can help me please.
AnirudhV13 6 years ago
NagyD1 6 years ago
The code is included in step 1.
Look for the file: snake.ino
黃莹 6 years ago
Hello, I want to get the photos of the breadboard of step 7 since I don't know the two LEDs put where for connection. Thank you so much if you available.
CelesteP12 6 years ago
Hi. I only have a 4 bit led clock display. Can I still use it for this project?