Snake Game With Arduino

16,071

49

19

Introduction: Snake Game With Arduino

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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!

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    19 Discussions

    0
    AliK287
    AliK287

    Question 5 months ago

    Hello, could you tell me what the code you use in this game please

    0
    KURUK1
    KURUK1

    Question 5 months ago

    C: \ Users \ USER \ AppData \ LocalLow \ Empyrean \ House Flipper Oyunu \ Crashes \ Crash_2018-06-02_182540 \ Downloads \ snake \ snake.ino: 7: 47: alert: 'int' den 'MD_MAX72XX'e kadar geçersiz dönüştürme :: moduleType_t '[
    -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

    2
    powercellar
    powercellar

    6 months ago

    Hey, I was wondering how you edit the MAX72xx.h file to set the type of matrix I'm using. I get an error code that tells me to "name a type."

    4
    Mister N
    Mister N

    Question 2 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

    20180420_131738.jpg20180420_131815.jpg
    0
    mataksik
    mataksik

    Answer 8 months 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);

    0
    tastyy
    tastyy

    Answer 1 year 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
    Osafter
    Osafter

    Reply 1 year ago

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

    2
    Osafter
    Osafter

    Question 2 years 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
    mataksik
    mataksik

    Answer 8 months 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);

    0
    AnnaB222
    AnnaB222

    Question 1 year ago

    It's ok if I have a 16X2 LCD and not a led display?

    0
    AnnaB222
    AnnaB222

    Question 1 year ago

    Hello, how can I change the matrix to 8X8? Please

    0
    JEF5
    JEF5

    Question 1 year 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
    0
    AnirudhV13
    AnirudhV13

    2 years ago

    Can I get the code please? Would really appreciate it

    0
    NagyD1
    NagyD1

    Reply 2 years ago

    The code is included in step 1.

    Look for the file: snake.ino

    0
    黃莹
    黃莹

    Question 2 years 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
    CelesteP12
    CelesteP12

    2 years ago

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

    0
    NagyD1
    NagyD1

    Reply 2 years 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
    CelesteP12
    CelesteP12

    Reply 2 years ago

    I believe the model is TM1637.

    0
    CelesteP12
    CelesteP12

    Reply 2 years ago

    It's very similar to this one.

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