This is a simple Snake Game targeted at children and for hobbyist. This game is made by using Arduino.
In this Snake Game Dot matrix display is used for displaying snake and food. And for score and game status like Game Start, and Game Over is displayed on 16×2 LCD. For controlling the game five push buttons are used (Start, Up, Down, Left and Right). To drive the Dot matrix display Shift registers are used. To start the game you have to press Start button and then use other Keys for direction.
Below are some snapshots of the entire project setup.
Fig. 1: Prototype of Arduino based Snake Game
Fig. 2: Image of LCD Module showing initial messages in Snake Game
Fig. 3: Image of Controller designed for Arduino based Snake Game
Fig. 4: Image of Dot Matrix Display used to play Snake Game
Fig. 5: Overview of Arduino based Snake Game
Circuit Description & Components Used
Circuit Description
There is a Dot matrix display used and connected with Shift Register 74595. Here two shift registers are used, one for driving the Columns and second for driving the Rows. Control pins of Column shift register (ds, sh, st) are directly connected to Arduino’s pin number 12, 10, 11 respectively and control pins of row shift register (ds, sh, st) are connected to Arduino’s pin number 9, 8, 7 respectively.
Fig. 6: Pin Diagram of Dot Matrix Display used in Snake Game
A 16×2 LCD is also connected with this circuit for displaying Score and Status of game like Game Over, Game Start etc. LCD’s data pins from D4 to D7 are connected to Arduino pin number (16, 15, 14, 13 / A2, A1, A0, 13) and Control Pins (RS, EN) of LCD’s are connected with Arduino’s pin number (A4, A3). For playing the Game, Control Keys (Down, Left, Right, Up, Start) are connected with Digital Pins (2, 3, 4, 5, 6) of Arduino.
Components Used
1. Arduino Pro Mini
2. 8×8 Dot Matrix Display
3. Shift Register 74595
4. Push Buttons
5. Register
6. Connecting Wire
7. Bread Board
8. Power Supply
You may also like:
Project Source Code
###
#includeLiquidCrystal lcd(18,17,16,15,14,13); #define ds_col 12 #define sh_col 10 #define st_col 11 #define ds_row 9 #define sh_row 8 #define st_row 7 int start=6; int left=3; int right=4; int up=5; int down=2; char Col[21]; char Row[21]; char addc,addr; int col(int temp) { switch(temp) { case 1: return 1;break; case 2: return 2; break; case 3: return 4; break; case 4: return 8; break; case 5: return 16; break; case 6: return 32; break; case 7: return 64; break; case 8: return 128; break; default: return 0; break; } } int row(int temp) { switch(temp) { case 1: return 1;break; case 2: return 2; break; case 3: return 4; break; case 4: return 8; break; case 5: return 16; break; case 6: return 32; break; case 7: return 64; break; case 8: return 128; break; default: return 0; break; } } void key() { if(digitalRead(left) == 0) { addr=0; if(addc!=-1) addc=-1; else addc=1; while(digitalRead(left) == 0); } if(digitalRead(right)== 0) { addr=0; if(addc!=1) addc=1; else addc=-1; while(digitalRead(right) == 0); } if(digitalRead(up)== 0) { addc=0; if(addr!=-1) addr=-1; else addr=1; while(digitalRead(up) == 0); } if(digitalRead(down) == 0) { addc=0; if(addr!=1) addr=1; else addr=-1; while(digitalRead(down) == 0); } } void Display(int temp) { int j,k; char colum,roww; for(j=0;j >=1; roww>>=1; digitalWrite(sh_col, HIGH); digitalWrite(sh_col, LOW); digitalWrite(sh_row, HIGH); digitalWrite(sh_row, LOW); } digitalWrite(st_col, HIGH); digitalWrite(st_col, LOW); digitalWrite(st_row, HIGH); digitalWrite(st_row, LOW); key(); delayMicroseconds(600); } } } void setup() { lcd.begin(16,2); pinMode(ds_col, OUTPUT); pinMode(sh_col, OUTPUT); pinMode(st_col, OUTPUT); pinMode(ds_row, OUTPUT); pinMode(sh_row, OUTPUT); pinMode(st_row, OUTPUT); pinMode(start, INPUT); pinMode(up, INPUT); pinMode(down, INPUT); pinMode(left, INPUT); pinMode(right, INPUT); lcd.setCursor(0,0); lcd.print(" Snake game on "); lcd.setCursor(0,1); lcd.print(" Dot Matrix "); delay(2000); lcd.setCursor(0,0); lcd.print(" By Saddam Khan "); lcd.setCursor(0,1); lcd.print("Engineers Garage"); delay(2000); } void loop() { int i,j,k,spd=40,score=0; j=k=0; addc=0; addr=1; lcd.clear(); lcd.setCursor(0,0); lcd.print("Score: "); lcd.print(score); while(1) { for(i=3;i<21;i++) { Row[i]=100; Col[i]=100; } Row[0]=rand()%8+1; Col[0]=rand()%8+1; Row[1]=1; Col[1]=1; Row[2]=2; Col[2]=1; j=2; k=1; while(k==1) { addc=0; addr=1; Display(1); lcd.clear(); lcd.setCursor(0,0); lcd.print("Score: "); lcd.print(score); if(digitalRead(start)==0) { k=2; spd=40; score=0; } } while(k==2) { Display(spd); if(Row[1]>8 || Col[1]>8 || Row[1]<0 || Col[1]<0) { Row[1]=1; Col[1]=1; k=1; lcd.setCursor(0,1); lcd.print("Game Over"); delay(5000); } if(Row[0]==Row[1]+addr && Col[0]==Col[1]+addc) { j++; spd=spd-2; score=score+5; lcd.clear(); lcd.setCursor(0,0); lcd.print("Score: "); lcd.print(score); Row[0]=rand()%8+1; Col[0]=rand()%8+1; } for(i=j;i>1;i--) { Col[i]=Col[i-1]; Row[i]=Row[i-1]; } Col[1]=Col[2]+addc; Row[1]=Row[2]+addr; } } } ###
Circuit Diagrams
Project Video
Filed Under: Electronic Projects
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.