Snake Game With Arduino

7,008

35

12

About: I'm a final grade student from Hungary. I like having fun with arduino, and build robots and stuff. I would like to study engineering later.

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:

MD_MAX72XX

MD_KeySwitch

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!

Share

    Recommendations

    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Optics Contest

      Optics Contest
    • Plastics Contest

      Plastics Contest

    12 Discussions

    0
    None
    JEF5

    Question 4 weeks ago

    hi! I'm having a problem with my dot matrix, I really hope that you can help me please.

    IMG_20181015_164452.jpgIMG_20181015_164458_HHT.jpg
    3
    None
    Mister N

    Question 6 months 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

    20180420_131738.jpg20180420_131815.jpg
    2 more answers
    0
    None
    tastyyMister N

    Answer 5 months ago

    Hey,

    you have to use an older version of the MD_MAX72xx library. Use the 2.10.0 vers. and it works fine!

    0
    None
    Osaftertastyy

    Reply 4 months ago

    hey, i had the same problem, and i did what you say, but the problem is not gone

    1
    None
    Osafter

    Question 5 months ago on Step 1

    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

    0
    None
    AnirudhV13

    7 months ago

    Can I get the code please? Would really appreciate it

    1 reply
    0
    None
    NagyD1AnirudhV13

    Reply 6 months ago

    The code is included in step 1.

    Look for the file: snake.ino

    0
    None
    黃莹

    Question 7 months ago on Step 9

    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.

    0
    None
    CelesteP12

    11 months ago

    Hi. I only have a 4 bit led clock display. Can I still use it for this project?

    3 replies
    0
    None
    NagyD1CelesteP12

    Reply 11 months ago

    Yes I think you can use that as well. But you might have to connect the pins an other way. If you send me the model information of your display I can help.

    0
    None
    CelesteP12CelesteP12

    Reply 11 months ago

    It's very similar to this one.

    https://www.amazon.com/gp/aw/d/B015SJ1PS8/ref=psd_mlt_bc_B015SJ1PS8