Project showcase
Arduino Memory Game

Arduino Memory Game © GPL3+

This makes a memory game using a memory array numbers.

  • 4,981 views
  • 1 comment
  • 27 respects

Components and supplies

Ph a000067 iso (1) wzec989qrf
Arduino Mega 2560
×1
7 segment display
×1
arduino kaypad 3x4
×1
11026 02
Jumper wires (generic)
×1
mini battery display
×1

Apps and online services

About this project

How it Works

This project uses an Arduino Mega control unit, Arduino 3x4 keypad, battery mini display and 7 segment display.

The numbers are random appear on the display and the player must enter a specific combination of numbers. When a player enters a good set of numbers on the battery display is increased one level.

How to Make this Project

How the Arduino Mega connects to the keypad. Connect the first pin on the left side to pin 8 on the Arduino. Pins from 8 pins to 2 pins on the Arduino Mega control unit.

The Display

The 7 segment display is connected to pins 35,37,39,41,47,49,53. See the schematics.

  • Mini battery dispaly has 4 pins GND, VCC, CLK, DIO.
  • DIO is connected to pin 9.
  • CLK is connected to the pin 10.

Libraries can be found at the following links:

Video:

Code

Arduino codeArduino
#include <Keypad.h>
#include<TM1651.h>

int CLK = 10;
int DIO = 9;
TM1651 batteryDisplay(CLK,DIO);
const byte ROWS = 4; 
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; 
byte colPins[COLS] = {4, 3, 2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int start[7]={39,41,53,49,47,37,35};
int ugasi[7]={0,0,0,0,0,0,0};
int jedan[7]={0,1,1,0,0,0,0};
int dva[7]={1,1,0,1,1,0,1};
int tri[7]={1,1,1,1,0,0,1};
int cetiri[7]={0,1,1,0,0,1,1};
int pet[7]={1,0,1,1,0,1,1};
int sest[7]={0,0,1,1,1,1,1};
int sedam[7]={1,1,1,0,0,0,0};
int osam[7]={1,1,1,1,1,1,1};
int devet[7]={1,1,1,0,0,1,1};
int nula[7]={1,1,1,1,1,1,0};
int pom=0;
int s[50];
int k=0;
int partija=0;

void setup(){
  Serial.begin(9600);
  Output(start);
  batteryDisplay.init();
  batteryDisplay.set(BRIGHTEST);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
  batteryDisplay.frame(FRAME_ON);
  randomSeed(analogRead(0));

  while(partija!=8){
    batteryDisplay.displayLevel(partija);
    s[k]=random(0,10);
    WriteDisplay(start,ugasi);
    delay(200);
    ispisi(s[k]);
    if(Konacno(k)!=0){
        WriteDisplay(start,ugasi);
        break;
     }
     partija++;k++;
  }//while end
}//setup end
  
void loop(){}

int Konacno(int k){
  int pom=0;
  while(pom<=k){
     char key = keypad.getKey();
     while(!key){ key = keypad.getKey(); }
     if(s[pom]!=K(key)) return -1;
     pom++;
     delay(400);
  }
  return 0;
}//end konacno
int K(char key){
  if(key=='1')return 1;
  else if(key=='2')return 2;
  else if(key=='3')return 3;
  else if(key=='4')return 4;
  else if(key=='5')return 5;
  else if(key=='6')return 6;
  else if(key=='7')return 7;
  else if(key=='8')return 8;
  else if(key=='9')return 9;
  else if(key=='0')return 0;
  else if(key=='*')return 10;
  else if(key=='#')return 11;
}

void ispisi(int x){
  switch(x){
    case 1:{ WriteDisplay(start,jedan); break; }
    case 2:{ WriteDisplay(start,dva); break; }
    case 3:{ WriteDisplay(start,tri); break; }
    case 4:{ WriteDisplay(start,cetiri); break; }
    case 5:{ WriteDisplay(start,pet); break; }
    case 6:{ WriteDisplay(start,sest); break; }
    case 7:{ WriteDisplay(start,sedam); break; }
    case 8:{ WriteDisplay(start,osam); break; }
    case 9:{ WriteDisplay(start,devet); break; }
    case 0:{ WriteDisplay(start,nula); break; }
  }
}
void WriteDisplay(int start[], int niz[]){
  for(int i=0;i<7;i++){
    if(niz[i]==0)digitalWrite(start[i],LOW);
    else digitalWrite(start[i],HIGH);
  }
}
void Output(int start[]){
  for(int i=0;i<7;i++){
    pinMode(start[i],OUTPUT);
  }
}
 
 
 

Schematics

arduino kaypad
Arduino and keypad bb phwgoluci4
7 segment dispaly
22222 ljsnbdu1sc

Comments

Similar projects you might like

Make an Arduino Memory Game

Project tutorial by Jeremie

  • 21,601 views
  • 39 comments
  • 46 respects

The Memory Game

Project showcase by Ikhsan Ismail

  • 3,084 views
  • 2 comments
  • 15 respects

Memory game

Project showcase by Anton Nazarenko

  • 3,208 views
  • 2 comments
  • 9 respects

Arduino Pocket Game Console + A-Maze - Maze Game

Project tutorial by Alojz Jakob

  • 11,876 views
  • 8 comments
  • 29 respects

Sezme: A Memory Game for the Arduino

by mariogianota

  • 1,201 views
  • 0 comments
  • 8 respects

Fast IR Game with Any Remote Control

Project showcase by mgbig

  • 2,981 views
  • 5 comments
  • 11 respects
Add projectSign up / Login