Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Snake Game Using Arduino

By Salman Khan January 9, 2022

 

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.

Prototype of Arduino based Snake Game

Fig. 1: Prototype of Arduino based Snake Game

Image of LCD Module showing initial messages in Snake Game

Fig. 2: Image of LCD Module showing initial messages in Snake Game

Image of Controller designed for Arduino based Snake Game

Fig. 3: Image of Controller designed for Arduino based Snake Game

Image of Dot Matrix Display used to play Snake Game

Fig. 4: Image of Dot Matrix Display used to play Snake Game

Overview of Arduino based 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.

Pin Diagram of Dot Matrix Display used in Snake Game

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:


  • What are the top tools for developing embedded software?

  • What is the Modbus protocol and how does it work?

  • What is a Robot Operating System (ROS)?

  • What is FreeRTOS?

  • What is LiDAR and how does it work?
  • Getting Started With Arduino With Simple LED Blinking Code Circuit Setup On Breadboard
    Getting started with Arduino – (Part 1/49)

Project Source Code

###

#include
LiquidCrystal 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

Circuit-Diagram-Arduino-Based-Snake-Game

Project Video


Filed Under: Electronic Projects
Tagged With: Arduino, dot matrix display, snake game
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Multiple DC/DC converters and a single input source
  • Xiaomi Mijia 1C Robot problem of going backwards while working
  • Will this TL084C based current clamp circuit work?
  • ADS optimization cockpit window does not open
  • Voltage mode pushpull is a nonsense SMPS?

RSS Electro-Tech-Online.com Discussions

  • Curved lines in PCB design
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz
  • using a RTC in SF basic
  • PIC KIT 3 not able to program dsPIC
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection
  • Convection-cooled power controller integrates EtherCat connectivity

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe