Make an Arduino Memory Game

A tutorial for beginners for making a memory game with an arduino and leds

Sep 13, 2017

105454 views

71 respects

Components and supplies

1

Arduino UNO

1

BreadBoard (Full size)

1

Mini speaker

1

Assorted LEDs

1

Jumper wires (generic)

1

330 ohm resistors

1

10k ohm resistors

Apps and platforms

1

Arduino IDE

Project description

Code

Memory Game Code

arduino

This is the entire code for the game. Simply copy and paste it in your favorite IDE and upload it to the Arduino.

Downloadable files

Diagram

Diagram

Fritzing Diagram

Fritzing Diagram

Diagram

Diagram

Fritzing Diagram

Fritzing Diagram

Comments

Only logged in users can leave comments

cuppermo

a year ago

Anonymus User@ Nah bro Is taking the Whole Comment Section 💀

cuppermo

a year ago

Hello Jeremie, I Just wanted to say This is an Absolutely Amazing Project and I am Interested Because I am a Beginner and For Beginners This would Be Awesome, So keep up the Great Work!

timothy2105

2 years ago

The arduino code isn't registering the button presses and is just playing the lose sequence. Do you know why this happens?

Anonymous user

2 years ago

I can't believe I got it to work right away. Great project!

Anonymous user

2 years ago

Hello Jeremie, I'm working on a school project. I have to make an arduino reaction game. I found this nice looking game. I build your memory game but I got a little problem.The left two lights are working proparly but the right two leds not, the right two leds turn on with the random order but if you press the button the arduino doesn't respond and you lose after the 2 seconds because the arduino thinks you didn't press the button. ( I don't use the speaker and I didn't change the code). I made a yt video so you can see what the arduino does.link (https://youtu.be/3VivkS3l_fg)I would appreciate it when you help me out with my problem.

1carmenk__

2 years ago

heyy did you get your solution?

Anonymous user

2 years ago

Hi there, how do i get in touch with you? I need something like this for a work project and would like advice on where to get it made for a one off interactive feature on an event stand.

Anonymous user

2 years ago

Hi Jeremie, I tried using your code, but when I try uploading it, it tells me: "Invalid library found in C:\\Users\\hhapp\\OneDrive\\Documents\\Arduino\\libraries\\EEL_FINAL: no headers files (.h) found in C:\\Users\\hhapp\\OneDrive\\Documents\\Arduino\\libraries\\EEL_FINAL" Do you have any advice?

Anonymous user

2 years ago

Can u plz check this code. It isn't working properly. void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978 #define CHOICE_OFF 0 //Used to control LEDs #define CHOICE_NONE 0 //Used to check buttons #define CHOICE_RED (1 << 0) #define CHOICE_GREEN (1 << 1) #define CHOICE_BLUE (1 << 2) #define CHOICE_YELLOW (1 << 3) #define LED_RED 10 #define LED_GREEN 3 #define LED_BLUE 13 #define LED_YELLOW 5 // Button pin definitions #define BUTTON_RED 9 #define BUTTON_GREEN 2 #define BUTTON_BLUE 12 #define BUTTON_YELLOW 6 // Buzzer pin definitions #define BUZZER1 4 #define BUZZER2 7 // Define game parameters #define ROUNDS_TO_WIN 13 //Number of rounds to succesfully remember before you win. 13 is do-able. #define ENTRY_TIME_LIMIT 3000 //Amount of time to press a button before game times out. 3000ms = 3 sec #define MODE_MEMORY 0 #define MODE_BATTLE 1 #define MODE_BEEGEES 2 // Game state variables byte gameMode = MODE_MEMORY; //By default, let's play the memory game byte gameBoard[32]; //Contains the combination of buttons as we advance byte gameRound = 0; //Counts the number of succesful rounds the player has made it through void setup() //Setup hardware inputs/outputs. These pins are defined in the hardware_versions header file //Enable pull ups on inputs pinMode(BUTTON_RED, INPUT_PULLUP); pinMode(BUTTON_GREEN, INPUT_PULLUP); pinMode(BUTTON_BLUE, INPUT_PULLUP); pinMode(BUTTON_YELLOW, INPUT_PULLUP); pinMode(LED_RED, OUTPUT); pinMode(LED_GREEN, OUTPUT); pinMode(LED_BLUE, OUTPUT); pinMode(LED_YELLOW, OUTPUT); pinMode(BUZZER1, OUTPUT); pinMode(BUZZER2, OUTPUT); //Mode checking gameMode = MODE_MEMORY; // By default, we're going to play the memory game // Check to see if the lower right button is pressed if (checkButton() == CHOICE_YELLOW) play_beegees(); // Check to see if upper right button is pressed if (checkButton() == CHOICE_GREEN) { gameMode = MODE_BATTLE; //Put game into battle mode //Turn on the upper right (green) LED setLEDs(CHOICE_GREEN); toner(CHOICE_GREEN, 150); setLEDs(CHOICE_RED | CHOICE_BLUE | CHOICE_YELLOW); // Turn on the other LEDs until you release button while(checkButton() != CHOICE_NONE) ; // Wait for user to stop pressing button //Now do nothing. Battle mode will be serviced in the main routine } play_winner(); // After setup is complete, say hello to the world } void loop() { attractMode(); // Blink lights while waiting for user to press a button // Indicate the start of game play setLEDs(CHOICE_RED | CHOICE_GREEN | CHOICE_BLUE | CHOICE_YELLOW); // Turn all LEDs on delay(1000); setLEDs(CHOICE_OFF); // Turn off LEDs delay(250); if (gameMode == MODE_MEMORY) { // Play memory game and handle result if (play_memory() == true) play_winner(); // Player won, play winner tones else play_loser(); // Player lost, play loser tones } if (gameMode == MODE_BATTLE) { play_battle(); // Play game until someone loses play_loser(); // Player lost, play loser tones } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //The following functions are related to game play only // Play the regular memory game // Returns 0 if player loses, or 1 if player wins boolean play_memory(void) { randomSeed(millis()); // Seed the random generator with random amount of millis() gameRound = 0; // Reset the game to the beginning while (gameRound < ROUNDS_TO_WIN) { add_to_moves(); // Add a button to the current moves, then play them back playMoves(); // Play back the current game board // Then require the player to repeat the sequence. for (byte currentMove = 0 ; currentMove < gameRound ; currentMove++) { byte choice = wait_for_button(); // See what button the user presses if (choice == 0) return false; // If wait timed out, player loses if (choice != gameBoard[currentMove]) return false; // If the choice is incorect, player loses } delay(1000); // Player was correct, delay before playing moves } return true; // Player made it through all the rounds to win! } // Play the special 2 player battle mode // A player begins by pressing a button then handing it to the other player // That player repeats the button and adds one, then passes back. // This function returns when someone loses boolean play_battle(void) { gameRound = 0; // Reset the game frame back to one frame while (1) // Loop until someone fails { byte newButton = wait_for_button(); // Wait for user to input next move gameBoard[gameRound++] = newButton; // Add this new button to the game array // Then require the player to repeat the sequence. for (byte currentMove = 0 ; currentMove < gameRound ; currentMove++) { byte choice = wait_for_button(); if (choice == 0) return false; // If wait timed out, player loses. if (choice != gameBoard[currentMove]) return false; // If the choice is incorect, player loses. } delay(100); // Give the user an extra 100ms to hand the game to the other player } return true; // We should never get here } // Plays the current contents of the game moves void playMoves(void) { for (byte currentMove = 0 ; currentMove < gameRound ; currentMove++) { toner(gameBoard[currentMove], 150); // Wait some amount of time between button playback // Shorten this to make game harder delay(150); // 150 works well. 75 gets fast. } } // Adds a new random button to the game sequence, by sampling the timer void add_to_moves(void) { byte newButton = random(0, 4); //min (included), max (exluded) // We have to convert this number, 0 to 3, to CHOICEs if(newButton == 0) newButton = CHOICE_RED; else if(newButton == 1) newButton = CHOICE_GREEN; else if(newButton == 2) newButton = CHOICE_BLUE; else if(newButton == 3) newButton = CHOICE_YELLOW; gameBoard[gameRound++] = newButton; // Add this new button to the game array } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //The following functions control the hardware // Lights a given LEDs // Pass in a byte that is made up from CHOICE_RED, CHOICE_YELLOW, etc void setLEDs(byte leds) { if ((leds & CHOICE_RED) != 0) digitalWrite(LED_RED, HIGH); else digitalWrite(LED_RED, LOW); if ((leds & CHOICE_GREEN) != 0) digitalWrite(LED_GREEN, HIGH); else digitalWrite(LED_GREEN, LOW); if ((leds & CHOICE_BLUE) != 0) digitalWrite(LED_BLUE, HIGH); else digitalWrite(LED_BLUE, LOW); if ((leds & CHOICE_YELLOW) != 0) digitalWrite(LED_YELLOW, HIGH); else digitalWrite(LED_YELLOW, LOW); } // Wait for a button to be pressed. // Returns one of LED colors (LED_RED, etc.) if successful, 0 if timed out byte wait_for_button(void) { long startTime = millis(); // Remember the time we started the this loop while ( (millis() - startTime) < ENTRY_TIME_LIMIT) // Loop until too much time has passed { byte button = checkButton(); if (button != CHOICE_NONE) { toner(button, 150); // Play the button the user just pressed while(checkButton() != CHOICE_NONE) ; // Now let's wait for user to release button delay(10); // This helps with debouncing and accidental double taps return button; } } return CHOICE_NONE; // If we get here, we've timed out! } // Returns a '1' bit in the position corresponding to CHOICE_RED, CHOICE_GREEN, etc. byte checkButton(void) { if (digitalRead(BUTTON_RED) == 0) return(CHOICE_RED); else if (digitalRead(BUTTON_GREEN) == 0) return(CHOICE_GREEN); else if (digitalRead(BUTTON_BLUE) == 0) return(CHOICE_BLUE); else if (digitalRead(BUTTON_YELLOW) == 0) return(CHOICE_YELLOW); return(CHOICE_NONE); // If no button is pressed, return none } // Light an LED and play tone // Red, upper left: 440Hz - 2.272ms - 1.136ms pulse // Green, upper right: 880Hz - 1.136ms - 0.568ms pulse // Blue, lower left: 587.33Hz - 1.702ms - 0.851ms pulse // Yellow, lower right: 784Hz - 1.276ms - 0.638ms pulse void toner(byte which, int buzz_length_ms) { setLEDs(which); //Turn on a given LED //Play the sound associated with the given LED switch(which) { case CHOICE_RED: buzz_sound(buzz_length_ms, 1136); break; case CHOICE_GREEN: buzz_sound(buzz_length_ms, 568); break; case CHOICE_BLUE: buzz_sound(buzz_length_ms, 851); break; case CHOICE_YELLOW: buzz_sound(buzz_length_ms, 638); break; } setLEDs(CHOICE_OFF); // Turn off all LEDs } // Toggle buzzer every buzz_delay_us, for a duration of buzz_length_ms. void buzz_sound(int buzz_length_ms, int buzz_delay_us) { // Convert total play time from milliseconds to microseconds long buzz_length_us = buzz_length_ms * (long)1000; // Loop until the remaining play time is less than a single buzz_delay_us while (buzz_length_us > (buzz_delay_us * 2)) { buzz_length_us -= buzz_delay_us * 2; //Decrease the remaining play time // Toggle the buzzer at various speeds digitalWrite(BUZZER1, LOW); digitalWrite(BUZZER2, HIGH); delayMicroseconds(buzz_delay_us); digitalWrite(BUZZER1, HIGH); digitalWrite(BUZZER2, LOW); delayMicroseconds(buzz_delay_us); } } // Play the winner sound and lights void play_winner(void) { setLEDs(CHOICE_GREEN | CHOICE_BLUE); winner_sound(); setLEDs(CHOICE_RED | CHOICE_YELLOW); winner_sound(); setLEDs(CHOICE_GREEN | CHOICE_BLUE); winner_sound(); setLEDs(CHOICE_RED | CHOICE_YELLOW); winner_sound(); } // Play the winner sound // This is just a unique (annoying) sound we came up with, there is no magic to it void winner_sound(void) { // Toggle the buzzer at various speeds for (byte x = 250 ; x > 70 ; x--) { for (byte y = 0 ; y < 3 ; y++) { digitalWrite(BUZZER2, HIGH); digitalWrite(BUZZER1, LOW); delayMicroseconds(x); digitalWrite(BUZZER2, LOW); digitalWrite(BUZZER1, HIGH); delayMicroseconds(x); } } } // Play the loser sound/lights void play_loser(void) { setLEDs(CHOICE_RED | CHOICE_GREEN); buzz_sound(255, 1500); setLEDs(CHOICE_BLUE | CHOICE_YELLOW); buzz_sound(255, 1500); setLEDs(CHOICE_RED | CHOICE_GREEN); buzz_sound(255, 1500); setLEDs(CHOICE_BLUE | CHOICE_YELLOW); buzz_sound(255, 1500); } // Show an "attract mode" display while waiting for user to press button. void attractMode(void) { while(1) { setLEDs(CHOICE_RED); delay(100); if (checkButton() != CHOICE_NONE) return; setLEDs(CHOICE_BLUE); delay(100); if (checkButton() != CHOICE_NONE) return; setLEDs(CHOICE_GREEN); delay(100); if (checkButton() != CHOICE_NONE) return; setLEDs(CHOICE_YELLOW); delay(100); if (checkButton() != CHOICE_NONE) return; } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // The following functions are related to Beegees Easter Egg only // Notes in the melody. Each note is about an 1/8th note, "0"s are rests. int melody[] = { NOTE_G4, NOTE_A4, 0, NOTE_C5, 0, 0, NOTE_G4, 0, 0, 0, NOTE_E4, 0, NOTE_D4, NOTE_E4, NOTE_G4, 0, NOTE_D4, NOTE_E4, 0, NOTE_G4, 0, 0, NOTE_D4, 0, NOTE_E4, 0, NOTE_G4, 0, NOTE_A4, 0, NOTE_C5, 0}; int noteDuration = 115; // This essentially sets the tempo, 115 is just about right for a disco groove :) int LEDnumber = 0; // Keeps track of which LED we are on during the beegees loop // Do nothing but play bad beegees music // This function is activated when user holds bottom right button during power up void play_beegees() { //Turn on the bottom right (yellow) LED setLEDs(CHOICE_YELLOW); toner(CHOICE_YELLOW, 150); setLEDs(CHOICE_RED | CHOICE_GREEN | CHOICE_BLUE); // Turn on the other LEDs until you release button while(checkButton() != CHOICE_NONE) ; // Wait for user to stop pressing button setLEDs(CHOICE_NONE); // Turn off LEDs delay(1000); // Wait a second before playing song digitalWrite(BUZZER1, LOW); // setup the "BUZZER1" side of the buzzer to stay low, while we play the tone on the other pin. while(checkButton() == CHOICE_NONE) //Play song until you press a button { // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 32; thisNote++) { changeLED(); tone(BUZZER2, melody[thisNote],noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(BUZZER2); } } } // Each time this function is called the board moves to the next LED void changeLED(void) { setLEDs(1 << LEDnumber); // Change the LED LEDnumber++; // Goto the next LED if(LEDnumber > 3) LEDnumber = 0; // Wrap the counter if needed } } Can u plz check this code. It isn't working properly.

Anonymous user

2 years ago

Would there be a way to give the player a second chance? If so lmk. Thanks!

zagri

2 years ago

hi ! i am simulating this project on www.tinkercad.com. but i have a big problem. please check my project and help me. project here: https://www.tinkercad.com/#/dashboard?type=all&collection=projects&id=egvYjhP89EM

zagri

2 years ago

i guess you changed your code in here. because i am copy-paste again and it worked ! thank you for answer and help :)

zagri

2 years ago

i am sorry. i forgot changed protect situation. could you try this link please: https://www.tinkercad.com/things/9rZWKbldczT

Jerepondumie

2 years ago

Hi Zagri, There was a nasty bug in my code! :( Sorry about that. line 152 in the code you used reads for(int i = 0; i <= noPins; i++){ and should actually be for(int i = 0; i < noPins; i++){ That little '=' that I removed caused the loop to go from 0 to 4, thus execute 5 times. As it's only got 4 LEDs, the fifth iteration would check pin 1 which is in an HIGH position. (I'm not 100% certain why) I guess I didn't have the problem on my project on the video because on my Arduino board, that pin was set on LOW... Weird! :D Removing the '=' makes the loop run 4 times only and only checks pins that are actually used. I have fixed it in the code on this project so you can either change the line in you tinkercad project or re-upload the modified code. It's still really difficult to play the game on the simulator now because the LEDS blink very fast (Too fast sometimes to memorize them all :) You could probably get past that by changing the delay values on line 100 and 102. The first one sets how long the LED stays on and the second one sets the time to wait before lighting the next one. Both in milliseconds Hope this helps Happy playing! J

Jerepondumie

2 years ago

Hi Zagri, I'd love to help but the link you provided seems to be for you to see it from your own account (When I click on it, it just brings me to a blank page) Could you please send me the link for your published project? J

Anonymous user

2 years ago

I followed the schematic and copied the code and when I started the game all the lights would not stop blinking at the same time and I was just wondering if possibly you may know why this might be happening, thanks.

Jerepondumie

2 years ago

Hello, at the start of the games, the lights are supposed to blink 5 times together slowly and if you lose, they blink together really quickly. There was an issue with my code a little while ago where the game would make you lose almost instantly after the first light blinked. I have fixed it in the code but if you downloaded the code too long ago, that might be your problem. Other than that, I unfortunately can't be much use. But you are more than welcome to PM me with some pictures of your circuit and I could check if I see something odd about it. (An extra pair of eyes often helps when looking at a breadboard :)

Anonymous user

2 years ago

Hello! I coppied the hole project but i can't use my last two buttons! only the first two can be pressed and work! Im sure my connection is ok cause all of the leds blink as planned. Any tips of how to fix it?

Jerepondumie

2 years ago

Hi Cats on Catnip, sorry for the late reply. This is an odd one... If all the LEDs blink and the button doesn't work, that would mean that your problem is in the 1K Ohm - button circuit. I would first confirm my wiring against the diagram (Use the one at the top of the story, with the blue LED, it's clearer) You could try inverting a non-working button with a working one to see if the button is fine. And do the same with the resistor (Though usually, when a resistor blows, you'll hear it and smell it :) Last I'd try to change Arduino ports. To do this, you only need to modify this line to match your new ports. _byte pins[] = {2, 13, 10, 8}; // Button input pins and LED ouput pins_ Just avoid using port 0 or 1 as they are also used by the serial interface and will behave weirdly because of the serial debugging being enabled. Also, don't use 5 either or you'll have to also change the sound pin value in the code. Good luck! Have fun!

Anonymous user

2 years ago

Thanks for this - was a great inspiration for enhancing a project I'd completed a year or so ago involving smartphone-controlled lights on a Lego Mini. Now it has a game function! Code at https://github.com/seasider1960/Lego_Mini_2.0 and a video at https://youtu.be/tejCt5SgZzY.

Jerepondumie

2 years ago

Hi Peter, Awesome idea! I went though both your instructables on the mini. I love the way you managed to squeeze all the wiring and the NodeMCU inside the little car so neatly. That's amazing work. I'm adding the link to your instructable at the bottom of my project so more people can see it!

labaguette

2 years ago

Cool project! Is it possible to make this game using the small breadboard as I don't have the full size one?

labaguette

2 years ago

Cool project! Is it possible to make this game using the small breadboard as I don't have the full size one?

Anonymous user

2 years ago

How do we make the player response wait time longer? I tried changing the first line to a greater number and it didn't change. Can you please help me with that? But overall, this is a fun game!

Jerepondumie

2 years ago

Hi TwoPilots, You changed the right line. For a noticeable difference, you will need to change it in 1000 increment, so 3000 = 3 seconds, 4000 = 4 seconds, etc... Glad you like the project. Have fun!

Anonymous user

2 years ago

Oh Ok. Thanks!

Anonymous user

2 years ago

Hi, I am trying to replicate this project and have everything connected to the breadboard and have implemented the code and I cannot get the lights to flash or anything to work. Any help would be greatly appreciated.

Jerepondumie

2 years ago

Hi Zha1997, There is a 3 second delay at the start, during which it looks like the Arduino is doing nothing. Because it is indeed doing nothing. After that, you should hear the beeps of the speaker at least. If the speaker is silent too, the batteries could be flat or the Arduino could be dead. (To test that, you can just load the Blink demo and check that the onboard LED flashes, then reload the program for this project when you're happy your Arduino isn't dead) Not being in front of your circuit, the only problem that I can think of is that the LEDs might have been plugged in the wrong way around. Make sure that the anode (long leg) of the LEDs are all on the side of the resistor in the board. If that doesn't help, re-look at your wiring and make sure that everything is connected properly, and to the correct column in the breadboard. My most common error with these breadboards is to plug the pin of a resistor in a column and the pin of the next component in the circuit in the hole next to it, in the next column. It looks right, but it isn't :) In your check, ensure that all the black wires (on the diagram) are connected to the same row of the board and all the red ones to the other row. I hope this puts you on your way to debugging your circuit. Good luck

Anonymous user

2 years ago

Jeremie your project looks great, but when I opened it, the lights and the speaker turned on but it kept doing that. So I need a quick response so I could play your game.

giobbino

2 years ago

Nice. Simon was a loved game and most people that was a child in the '70s remember it and many tried to build his own version with Arduino, LOL. This is my version: https://create.arduino.cc/projecthub/giobbino/simon-clone-with-arduino-nano-9edb51

Anonymous user

2 years ago

Hey Jeremie , I was asking that can you create the same project with lcd 1602 display that will be really fun. I want to build this for my little brother. Thanks waiting for your reply

Anonymous user

2 years ago

How would I change the code to make the lights blink more randomly? Almost every game one or more blink three times in a row.

giobbino

2 years ago

Yep, the random function in Arduino isn't sooo random LOL I had the same problem (and I solved it of course). Take a look to my project: https://create.arduino.cc/projecthub/giobbino/simon-clone-with-arduino-nano-9edb51

Anonymous user

2 years ago

is cool :-)

Anonymous user

2 years ago

This works great for me. However, when i try to take out all the Serial stuff, it stops working. Your comments say you can take out Serial communication as long as you take out every Serial line, and this makes sense to me but the game stops working for me

Anonymous user

2 years ago

The code stops running when I add certain libraries as well

Jerepondumie

2 years ago

Hey Akafoury, This is a tough one... I see that in my program, I forgot to comment on lines 94-97 that they should be removed too. When changing the program, 2 things can happen, you can either miss something, or delete something you shouldn't have. In this case, if you missed something, there's a good chance the program will not compile and tell you what line it's upset about. If you deleted something you shouldn't have, that becomes a little trickier. The program could be working and compiling but a bug would have appeared. For example, if you accidentally deleted line 98 ( digitalWrite(sequence[i], HIGH); ), the program would compile, and work almost exactly as intended except that it's the line that turns the LED on when showing the sequence, so without it, nothing will light up. The only thing I can suggest is to open the original program, and load it back onto your Arduino. That will ensure that the problem isn't with a connection that shifted or anything hardware related. Then you could open your version of the program next to it and verify that you haven't removed an extra line by accident by looking at the code on both sides and comparing them. If you're really stuck, you are welcome to paste your code in this comment and I'll check it out on my side. But I'll probably take a bit longer to reply because I'll have to build everything again. Hope this helps at least a little. J

Jerepondumie

2 years ago

Hello again, Regarding the libraries, I can't tell you much unfortunately. The problem could be caused by the library itself. Maybe a function in there that would have the same name as one of the existing ones in the program. or maybe the library using certain pins by default that my program is also using... You could try working the other way and starting the project you want to by writing the code that uses those libraries in a new program and getting that to work and then integrating the pieces of this project you want to use into the new program. That way you'll possibly see the problem appear from a different angle. And like above, if you tell me what library is troubling you, I can play with it here and see... Cheers J

Anonymous user

2 years ago

is there any way this can be made to work in a WEMOS D1?

Jerepondumie

2 years ago

Hi Gregory, you probably can. I don't have one of those so I can't test but according to this "https://arduino.stackexchange.com/questions/49119/arduino-uno-r3-to-wemos-d1-r2-project-migration-pinout-problems" you can just select the pins you want on your WEMOS and modify the code according to this. You only need to change byte soundPin = 5; byte pins[] = {2, 13, 10, 8}; to use the pins you selected on your board.

Anonymous user

2 years ago

Thank you for the project :) I've only just started to get into Arduino and this is actually my first game. Followed the diagram and uploaded the sketch and worked perfectly. Only issue I had is I made on a small bread board, half size? And was a little cramped, but worked out I could remove a couple of wires and put the resistor straight to the negative which freed up a bit more room. But it still worked first go and is my favourite project yet :)

Anonymous user

2 years ago

Put all together and uploaded the sketch. The first LED is the only one that flashes 5 times and then a random LED lights up, but then immediately the first LED flashes fast 5 times and resets the game. The games doesn't wait for an input, it's just looping. What could be wrong? Thanks

Jerepondumie

2 years ago

Hi Daniel, This looks like the bug I had in the code a little while ago. I fixed that [confused emoticon goes here]. You can re-download the code or fix it yourself: In short the problem might be with line 152 in the code. If it reads, for(int i = 0; i <= noPins; i++){ It's wrong :) It should read for(int i = 0; i < noPins; i++){ That little '=' there is making the loop run to an array position that's in a memory location where the value is... Whatever it is at the time. This causes the code behave erratically. If this doesn't solve your problem, please let me know and I'll see what else could be misbehaving.

Jerepondumie

2 years ago

Awesome idea! Somewhere on hackster, there's an Upgrade to the memory game where I did something similar with an LCD. But would love to see your code for the 7 segment display if that's ok. You should publish it!

Anonymous user

2 years ago

Hey Jeremie Thanks for your reply. Meanwhile I found the problem. It seems there's something wrong with my breadboard, cause the + and - rails didn't make it all the way down somehow. I added some cables and now it works like a charm. I also added a 7-segment display to show the current level. Works just fine! Thank you very much!

1carmenk__

2 years ago

heyy, can you please contact me. i have some questions about it since im doing it for my school project. i would appreciate it sooo much. anyone who knows anything about it, please reach me, ill give you my e mail. thank you so much much love <3

Anonymous user

2 years ago

I copied the code and the board and it still does not work.Can you help? Also does the resistor color madder?

Anonymous user

2 years ago

Hi Jeremie, thanks for the project, it works great. I'm adapting it for use in an escape room style game where they have to beat 10 - 15 levels to unlock something. One question I have is that if I remove the 10k resistor the circuit still functions correctly. Is it there to pull the digital pin low or is there another reason? Thanks Andy

Jerepondumie

2 years ago

Hi Andy354, Yes, it's only purpose is to pull the pin to low when it's on input. I always put one in case some magnetic field starts inducing current on my circuit. Please post your escape the room game somewhere when you're done. I'd love to see it.

Anonymous user

2 years ago

Hi how do I change the input from a button push to LDR input in the code?

Anonymous user

2 years ago

THIS PROGRAM DOO DOO

Jerepondumie

2 years ago

Thank you for the constructive criticism :D If you can make it better, please feel free to post the code. I'm not very good with C++ and am happy to learn.

Anonymous user

3 years ago

Would there be a way to give the player a second chance? If so lmk. Thanks!

giobbino

3 years ago

Nice. Simon was a loved game and most people that was a child in the '70s remember it and many tried to build his own version with Arduino, LOL. This is my version: https://create.arduino.cc/projecthub/giobbino/simon-clone-with-arduino-nano-9edb51

Anonymous user

3 years ago

Hi how do I change the input from a button push to LDR input in the code?

Anonymous user

3 years ago

Hey Jeremie , I was asking that can you create the same project with lcd 1602 display that will be really fun. I want to build this for my little brother. Thanks waiting for your reply

Anonymous user

3 years ago

How would I change the code to make the lights blink more randomly? Almost every game one or more blink three times in a row.

giobbino

2 years ago

Yep, the random function in Arduino isn't sooo random LOL I had the same problem (and I solved it of course). Take a look to my project: https://create.arduino.cc/projecthub/giobbino/simon-clone-with-arduino-nano-9edb51

noraa9186

3 years ago

Thank you for the project :) I've only just started to get into Arduino and this is actually my first game. Followed the diagram and uploaded the sketch and worked perfectly. Only issue I had is I made on a small bread board, half size? And was a little cramped, but worked out I could remove a couple of wires and put the resistor straight to the negative which freed up a bit more room. But it still worked first go and is my favourite project yet :)

1carmenk__

4 years ago

heyy, can you please contact me. i have some questions about it since im doing it for my school project. i would appreciate it sooo much. anyone who knows anything about it, please reach me, ill give you my e mail. thank you so much much love <3

Anonymous user

5 years ago

I can't believe I got it to work right away. Great project!

Anonymous user

5 years ago

Hi Jeremie, I tried using your code, but when I try uploading it, it tells me: "Invalid library found in C:\\Users\\hhapp\\OneDrive\\Documents\\Arduino\\libraries\\EEL_FINAL: no headers files (.h) found in C:\\Users\\hhapp\\OneDrive\\Documents\\Arduino\\libraries\\EEL_FINAL" Do you have any advice?

Anonymous user

6 years ago

Hello Jeremie, I'm working on a school project. I have to make an arduino reaction game. I found this nice looking game. I build your memory game but I got a little problem.The left two lights are working proparly but the right two leds not, the right two leds turn on with the random order but if you press the button the arduino doesn't respond and you lose after the 2 seconds because the arduino thinks you didn't press the button. ( I don't use the speaker and I didn't change the code). I made a yt video so you can see what the arduino does.link (https://youtu.be/3VivkS3l_fg)I would appreciate it when you help me out with my problem.

1carmenk__

2 years ago

heyy did you get your solution?

Anonymous user

6 years ago

Can u plz check this code. It isn't working properly. void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978 #define CHOICE_OFF 0 //Used to control LEDs #define CHOICE_NONE 0 //Used to check buttons #define CHOICE_RED (1 << 0) #define CHOICE_GREEN (1 << 1) #define CHOICE_BLUE (1 << 2) #define CHOICE_YELLOW (1 << 3) #define LED_RED 10 #define LED_GREEN 3 #define LED_BLUE 13 #define LED_YELLOW 5 // Button pin definitions #define BUTTON_RED 9 #define BUTTON_GREEN 2 #define BUTTON_BLUE 12 #define BUTTON_YELLOW 6 // Buzzer pin definitions #define BUZZER1 4 #define BUZZER2 7 // Define game parameters #define ROUNDS_TO_WIN 13 //Number of rounds to succesfully remember before you win. 13 is do-able. #define ENTRY_TIME_LIMIT 3000 //Amount of time to press a button before game times out. 3000ms = 3 sec #define MODE_MEMORY 0 #define MODE_BATTLE 1 #define MODE_BEEGEES 2 // Game state variables byte gameMode = MODE_MEMORY; //By default, let's play the memory game byte gameBoard[32]; //Contains the combination of buttons as we advance byte gameRound = 0; //Counts the number of succesful rounds the player has made it through void setup() //Setup hardware inputs/outputs. These pins are defined in the hardware_versions header file //Enable pull ups on inputs pinMode(BUTTON_RED, INPUT_PULLUP); pinMode(BUTTON_GREEN, INPUT_PULLUP); pinMode(BUTTON_BLUE, INPUT_PULLUP); pinMode(BUTTON_YELLOW, INPUT_PULLUP); pinMode(LED_RED, OUTPUT); pinMode(LED_GREEN, OUTPUT); pinMode(LED_BLUE, OUTPUT); pinMode(LED_YELLOW, OUTPUT); pinMode(BUZZER1, OUTPUT); pinMode(BUZZER2, OUTPUT); //Mode checking gameMode = MODE_MEMORY; // By default, we're going to play the memory game // Check to see if the lower right button is pressed if (checkButton() == CHOICE_YELLOW) play_beegees(); // Check to see if upper right button is pressed if (checkButton() == CHOICE_GREEN) { gameMode = MODE_BATTLE; //Put game into battle mode //Turn on the upper right (green) LED setLEDs(CHOICE_GREEN); toner(CHOICE_GREEN, 150); setLEDs(CHOICE_RED | CHOICE_BLUE | CHOICE_YELLOW); // Turn on the other LEDs until you release button while(checkButton() != CHOICE_NONE) ; // Wait for user to stop pressing button //Now do nothing. Battle mode will be serviced in the main routine } play_winner(); // After setup is complete, say hello to the world } void loop() { attractMode(); // Blink lights while waiting for user to press a button // Indicate the start of game play setLEDs(CHOICE_RED | CHOICE_GREEN | CHOICE_BLUE | CHOICE_YELLOW); // Turn all LEDs on delay(1000); setLEDs(CHOICE_OFF); // Turn off LEDs delay(250); if (gameMode == MODE_MEMORY) { // Play memory game and handle result if (play_memory() == true) play_winner(); // Player won, play winner tones else play_loser(); // Player lost, play loser tones } if (gameMode == MODE_BATTLE) { play_battle(); // Play game until someone loses play_loser(); // Player lost, play loser tones } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //The following functions are related to game play only // Play the regular memory game // Returns 0 if player loses, or 1 if player wins boolean play_memory(void) { randomSeed(millis()); // Seed the random generator with random amount of millis() gameRound = 0; // Reset the game to the beginning while (gameRound < ROUNDS_TO_WIN) { add_to_moves(); // Add a button to the current moves, then play them back playMoves(); // Play back the current game board // Then require the player to repeat the sequence. for (byte currentMove = 0 ; currentMove < gameRound ; currentMove++) { byte choice = wait_for_button(); // See what button the user presses if (choice == 0) return false; // If wait timed out, player loses if (choice != gameBoard[currentMove]) return false; // If the choice is incorect, player loses } delay(1000); // Player was correct, delay before playing moves } return true; // Player made it through all the rounds to win! } // Play the special 2 player battle mode // A player begins by pressing a button then handing it to the other player // That player repeats the button and adds one, then passes back. // This function returns when someone loses boolean play_battle(void) { gameRound = 0; // Reset the game frame back to one frame while (1) // Loop until someone fails { byte newButton = wait_for_button(); // Wait for user to input next move gameBoard[gameRound++] = newButton; // Add this new button to the game array // Then require the player to repeat the sequence. for (byte currentMove = 0 ; currentMove < gameRound ; currentMove++) { byte choice = wait_for_button(); if (choice == 0) return false; // If wait timed out, player loses. if (choice != gameBoard[currentMove]) return false; // If the choice is incorect, player loses. } delay(100); // Give the user an extra 100ms to hand the game to the other player } return true; // We should never get here } // Plays the current contents of the game moves void playMoves(void) { for (byte currentMove = 0 ; currentMove < gameRound ; currentMove++) { toner(gameBoard[currentMove], 150); // Wait some amount of time between button playback // Shorten this to make game harder delay(150); // 150 works well. 75 gets fast. } } // Adds a new random button to the game sequence, by sampling the timer void add_to_moves(void) { byte newButton = random(0, 4); //min (included), max (exluded) // We have to convert this number, 0 to 3, to CHOICEs if(newButton == 0) newButton = CHOICE_RED; else if(newButton == 1) newButton = CHOICE_GREEN; else if(newButton == 2) newButton = CHOICE_BLUE; else if(newButton == 3) newButton = CHOICE_YELLOW; gameBoard[gameRound++] = newButton; // Add this new button to the game array } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //The following functions control the hardware // Lights a given LEDs // Pass in a byte that is made up from CHOICE_RED, CHOICE_YELLOW, etc void setLEDs(byte leds) { if ((leds & CHOICE_RED) != 0) digitalWrite(LED_RED, HIGH); else digitalWrite(LED_RED, LOW); if ((leds & CHOICE_GREEN) != 0) digitalWrite(LED_GREEN, HIGH); else digitalWrite(LED_GREEN, LOW); if ((leds & CHOICE_BLUE) != 0) digitalWrite(LED_BLUE, HIGH); else digitalWrite(LED_BLUE, LOW); if ((leds & CHOICE_YELLOW) != 0) digitalWrite(LED_YELLOW, HIGH); else digitalWrite(LED_YELLOW, LOW); } // Wait for a button to be pressed. // Returns one of LED colors (LED_RED, etc.) if successful, 0 if timed out byte wait_for_button(void) { long startTime = millis(); // Remember the time we started the this loop while ( (millis() - startTime) < ENTRY_TIME_LIMIT) // Loop until too much time has passed { byte button = checkButton(); if (button != CHOICE_NONE) { toner(button, 150); // Play the button the user just pressed while(checkButton() != CHOICE_NONE) ; // Now let's wait for user to release button delay(10); // This helps with debouncing and accidental double taps return button; } } return CHOICE_NONE; // If we get here, we've timed out! } // Returns a '1' bit in the position corresponding to CHOICE_RED, CHOICE_GREEN, etc. byte checkButton(void) { if (digitalRead(BUTTON_RED) == 0) return(CHOICE_RED); else if (digitalRead(BUTTON_GREEN) == 0) return(CHOICE_GREEN); else if (digitalRead(BUTTON_BLUE) == 0) return(CHOICE_BLUE); else if (digitalRead(BUTTON_YELLOW) == 0) return(CHOICE_YELLOW); return(CHOICE_NONE); // If no button is pressed, return none } // Light an LED and play tone // Red, upper left: 440Hz - 2.272ms - 1.136ms pulse // Green, upper right: 880Hz - 1.136ms - 0.568ms pulse // Blue, lower left: 587.33Hz - 1.702ms - 0.851ms pulse // Yellow, lower right: 784Hz - 1.276ms - 0.638ms pulse void toner(byte which, int buzz_length_ms) { setLEDs(which); //Turn on a given LED //Play the sound associated with the given LED switch(which) { case CHOICE_RED: buzz_sound(buzz_length_ms, 1136); break; case CHOICE_GREEN: buzz_sound(buzz_length_ms, 568); break; case CHOICE_BLUE: buzz_sound(buzz_length_ms, 851); break; case CHOICE_YELLOW: buzz_sound(buzz_length_ms, 638); break; } setLEDs(CHOICE_OFF); // Turn off all LEDs } // Toggle buzzer every buzz_delay_us, for a duration of buzz_length_ms. void buzz_sound(int buzz_length_ms, int buzz_delay_us) { // Convert total play time from milliseconds to microseconds long buzz_length_us = buzz_length_ms * (long)1000; // Loop until the remaining play time is less than a single buzz_delay_us while (buzz_length_us > (buzz_delay_us * 2)) { buzz_length_us -= buzz_delay_us * 2; //Decrease the remaining play time // Toggle the buzzer at various speeds digitalWrite(BUZZER1, LOW); digitalWrite(BUZZER2, HIGH); delayMicroseconds(buzz_delay_us); digitalWrite(BUZZER1, HIGH); digitalWrite(BUZZER2, LOW); delayMicroseconds(buzz_delay_us); } } // Play the winner sound and lights void play_winner(void) { setLEDs(CHOICE_GREEN | CHOICE_BLUE); winner_sound(); setLEDs(CHOICE_RED | CHOICE_YELLOW); winner_sound(); setLEDs(CHOICE_GREEN | CHOICE_BLUE); winner_sound(); setLEDs(CHOICE_RED | CHOICE_YELLOW); winner_sound(); } // Play the winner sound // This is just a unique (annoying) sound we came up with, there is no magic to it void winner_sound(void) { // Toggle the buzzer at various speeds for (byte x = 250 ; x > 70 ; x--) { for (byte y = 0 ; y < 3 ; y++) { digitalWrite(BUZZER2, HIGH); digitalWrite(BUZZER1, LOW); delayMicroseconds(x); digitalWrite(BUZZER2, LOW); digitalWrite(BUZZER1, HIGH); delayMicroseconds(x); } } } // Play the loser sound/lights void play_loser(void) { setLEDs(CHOICE_RED | CHOICE_GREEN); buzz_sound(255, 1500); setLEDs(CHOICE_BLUE | CHOICE_YELLOW); buzz_sound(255, 1500); setLEDs(CHOICE_RED | CHOICE_GREEN); buzz_sound(255, 1500); setLEDs(CHOICE_BLUE | CHOICE_YELLOW); buzz_sound(255, 1500); } // Show an "attract mode" display while waiting for user to press button. void attractMode(void) { while(1) { setLEDs(CHOICE_RED); delay(100); if (checkButton() != CHOICE_NONE) return; setLEDs(CHOICE_BLUE); delay(100); if (checkButton() != CHOICE_NONE) return; setLEDs(CHOICE_GREEN); delay(100); if (checkButton() != CHOICE_NONE) return; setLEDs(CHOICE_YELLOW); delay(100); if (checkButton() != CHOICE_NONE) return; } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // The following functions are related to Beegees Easter Egg only // Notes in the melody. Each note is about an 1/8th note, "0"s are rests. int melody[] = { NOTE_G4, NOTE_A4, 0, NOTE_C5, 0, 0, NOTE_G4, 0, 0, 0, NOTE_E4, 0, NOTE_D4, NOTE_E4, NOTE_G4, 0, NOTE_D4, NOTE_E4, 0, NOTE_G4, 0, 0, NOTE_D4, 0, NOTE_E4, 0, NOTE_G4, 0, NOTE_A4, 0, NOTE_C5, 0}; int noteDuration = 115; // This essentially sets the tempo, 115 is just about right for a disco groove :) int LEDnumber = 0; // Keeps track of which LED we are on during the beegees loop // Do nothing but play bad beegees music // This function is activated when user holds bottom right button during power up void play_beegees() { //Turn on the bottom right (yellow) LED setLEDs(CHOICE_YELLOW); toner(CHOICE_YELLOW, 150); setLEDs(CHOICE_RED | CHOICE_GREEN | CHOICE_BLUE); // Turn on the other LEDs until you release button while(checkButton() != CHOICE_NONE) ; // Wait for user to stop pressing button setLEDs(CHOICE_NONE); // Turn off LEDs delay(1000); // Wait a second before playing song digitalWrite(BUZZER1, LOW); // setup the "BUZZER1" side of the buzzer to stay low, while we play the tone on the other pin. while(checkButton() == CHOICE_NONE) //Play song until you press a button { // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 32; thisNote++) { changeLED(); tone(BUZZER2, melody[thisNote],noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(BUZZER2); } } } // Each time this function is called the board moves to the next LED void changeLED(void) { setLEDs(1 << LEDnumber); // Change the LED LEDnumber++; // Goto the next LED if(LEDnumber > 3) LEDnumber = 0; // Wrap the counter if needed } } Can u plz check this code. It isn't working properly.

castagna_joshua

6 years ago

I copied the code and the board and it still does not work.Can you help? Also does the resistor color madder?

Anonymous user

6 years ago

Jeremie your project looks great, but when I opened it, the lights and the speaker turned on but it kept doing that. So I need a quick response so I could play your game.

andy354

6 years ago

Hi Jeremie, thanks for the project, it works great. I'm adapting it for use in an escape room style game where they have to beat 10 - 15 levels to unlock something. One question I have is that if I remove the 10k resistor the circuit still functions correctly. Is it there to pull the digital pin low or is there another reason? Thanks Andy

Jerepondumie

2 years ago

Hi Andy354, Yes, it's only purpose is to pull the pin to low when it's on input. I always put one in case some magnetic field starts inducing current on my circuit. Please post your escape the room game somewhere when you're done. I'd love to see it.

Anonymous user

6 years ago

Hello! I coppied the hole project but i can't use my last two buttons! only the first two can be pressed and work! Im sure my connection is ok cause all of the leds blink as planned. Any tips of how to fix it?

Jerepondumie

2 years ago

Hi Cats on Catnip, sorry for the late reply. This is an odd one... If all the LEDs blink and the button doesn't work, that would mean that your problem is in the 1K Ohm - button circuit. I would first confirm my wiring against the diagram (Use the one at the top of the story, with the blue LED, it's clearer) You could try inverting a non-working button with a working one to see if the button is fine. And do the same with the resistor (Though usually, when a resistor blows, you'll hear it and smell it :) Last I'd try to change Arduino ports. To do this, you only need to modify this line to match your new ports. _byte pins[] = {2, 13, 10, 8}; // Button input pins and LED ouput pins_ Just avoid using port 0 or 1 as they are also used by the serial interface and will behave weirdly because of the serial debugging being enabled. Also, don't use 5 either or you'll have to also change the sound pin value in the code. Good luck! Have fun!

Anonymous user

6 years ago

Thanks for this - was a great inspiration for enhancing a project I'd completed a year or so ago involving smartphone-controlled lights on a Lego Mini. Now it has a game function! Code at https://github.com/seasider1960/Lego_Mini_2.0 and a video at https://youtu.be/tejCt5SgZzY.

Jerepondumie

2 years ago

Hi Peter, Awesome idea! I went though both your instructables on the mini. I love the way you managed to squeeze all the wiring and the NodeMCU inside the little car so neatly. That's amazing work. I'm adding the link to your instructable at the bottom of my project so more people can see it!

Anonymous user

6 years ago

is cool :-)

Anonymous user

6 years ago

is there any way this can be made to work in a WEMOS D1?

Jerepondumie

2 years ago

Hi Gregory, you probably can. I don't have one of those so I can't test but according to this "https://arduino.stackexchange.com/questions/49119/arduino-uno-r3-to-wemos-d1-r2-project-migration-pinout-problems" you can just select the pins you want on your WEMOS and modify the code according to this. You only need to change byte soundPin = 5; byte pins[] = {2, 13, 10, 8}; to use the pins you selected on your board.

Anonymous user

6 years ago

Put all together and uploaded the sketch. The first LED is the only one that flashes 5 times and then a random LED lights up, but then immediately the first LED flashes fast 5 times and resets the game. The games doesn't wait for an input, it's just looping. What could be wrong? Thanks

Jerepondumie

2 years ago

Hi Daniel, This looks like the bug I had in the code a little while ago. I fixed that [confused emoticon goes here]. You can re-download the code or fix it yourself: In short the problem might be with line 152 in the code. If it reads, for(int i = 0; i <= noPins; i++){ It's wrong :) It should read for(int i = 0; i < noPins; i++){ That little '=' there is making the loop run to an array position that's in a memory location where the value is... Whatever it is at the time. This causes the code behave erratically. If this doesn't solve your problem, please let me know and I'll see what else could be misbehaving.

Jerepondumie

2 years ago

Awesome idea! Somewhere on hackster, there's an Upgrade to the memory game where I did something similar with an LCD. But would love to see your code for the 7 segment display if that's ok. You should publish it!

Anonymous user

2 years ago

Hey Jeremie Thanks for your reply. Meanwhile I found the problem. It seems there's something wrong with my breadboard, cause the + and - rails didn't make it all the way down somehow. I added some cables and now it works like a charm. I also added a 7-segment display to show the current level. Works just fine! Thank you very much!

Anonymous user

6 years ago

I followed the schematic and copied the code and when I started the game all the lights would not stop blinking at the same time and I was just wondering if possibly you may know why this might be happening, thanks.

Jerepondumie

2 years ago

Hello, at the start of the games, the lights are supposed to blink 5 times together slowly and if you lose, they blink together really quickly. There was an issue with my code a little while ago where the game would make you lose almost instantly after the first light blinked. I have fixed it in the code but if you downloaded the code too long ago, that might be your problem. Other than that, I unfortunately can't be much use. But you are more than welcome to PM me with some pictures of your circuit and I could check if I see something odd about it. (An extra pair of eyes often helps when looking at a breadboard :)

zagri

6 years ago

hi ! i am simulating this project on www.tinkercad.com. but i have a big problem. please check my project and help me. project here: https://www.tinkercad.com/#/dashboard?type=all&collection=projects&id=egvYjhP89EM

zagri

2 years ago

i am sorry. i forgot changed protect situation. could you try this link please: https://www.tinkercad.com/things/9rZWKbldczT

Jerepondumie

2 years ago

Hi Zagri, There was a nasty bug in my code! :( Sorry about that. line 152 in the code you used reads for(int i = 0; i <= noPins; i++){ and should actually be for(int i = 0; i < noPins; i++){ That little '=' that I removed caused the loop to go from 0 to 4, thus execute 5 times. As it's only got 4 LEDs, the fifth iteration would check pin 1 which is in an HIGH position. (I'm not 100% certain why) I guess I didn't have the problem on my project on the video because on my Arduino board, that pin was set on LOW... Weird! :D Removing the '=' makes the loop run 4 times only and only checks pins that are actually used. I have fixed it in the code on this project so you can either change the line in you tinkercad project or re-upload the modified code. It's still really difficult to play the game on the simulator now because the LEDS blink very fast (Too fast sometimes to memorize them all :) You could probably get past that by changing the delay values on line 100 and 102. The first one sets how long the LED stays on and the second one sets the time to wait before lighting the next one. Both in milliseconds Hope this helps Happy playing! J

zagri

2 years ago

i guess you changed your code in here. because i am copy-paste again and it worked ! thank you for answer and help :)

Jerepondumie

2 years ago

Hi Zagri, I'd love to help but the link you provided seems to be for you to see it from your own account (When I click on it, it just brings me to a blank page) Could you please send me the link for your published project? J

Anonymous user

6 years ago

THIS PROGRAM DOO DOO

Jerepondumie

2 years ago

Thank you for the constructive criticism :D If you can make it better, please feel free to post the code. I'm not very good with C++ and am happy to learn.

WrichikBasu

7 years ago

Can you please share a video of the game (when you're playing)? I just want to see how it works. Also, can a LCD screen be combined with it giving instructions, like: "Memorise this:", "You Lost", "Current score", etc.? If yes, what will be the new code and schematic?

Jerepondumie

2 years ago

Hi WrichikBasu, I added a video at the end of the story, of my housemate playing with a version I built later onto a small PCB. (The code and schematics are exactly the same, Only it uses a nano instead of a UNO) The screen idea is awesome! I've been meaning to make a post with an LCD so I might just try this. I have a few posts I want to finish before I get there so no promises regarding when :) Don't hesitate to follow me to see when this gets done!

Anonymous user

7 years ago

Hi there, how do i get in touch with you? I need something like this for a work project and would like advice on where to get it made for a one off interactive feature on an event stand.

Anonymous user

7 years ago

This works great for me. However, when i try to take out all the Serial stuff, it stops working. Your comments say you can take out Serial communication as long as you take out every Serial line, and this makes sense to me but the game stops working for me

Jerepondumie

2 years ago

Hey Akafoury, This is a tough one... I see that in my program, I forgot to comment on lines 94-97 that they should be removed too. When changing the program, 2 things can happen, you can either miss something, or delete something you shouldn't have. In this case, if you missed something, there's a good chance the program will not compile and tell you what line it's upset about. If you deleted something you shouldn't have, that becomes a little trickier. The program could be working and compiling but a bug would have appeared. For example, if you accidentally deleted line 98 ( digitalWrite(sequence[i], HIGH); ), the program would compile, and work almost exactly as intended except that it's the line that turns the LED on when showing the sequence, so without it, nothing will light up. The only thing I can suggest is to open the original program, and load it back onto your Arduino. That will ensure that the problem isn't with a connection that shifted or anything hardware related. Then you could open your version of the program next to it and verify that you haven't removed an extra line by accident by looking at the code on both sides and comparing them. If you're really stuck, you are welcome to paste your code in this comment and I'll check it out on my side. But I'll probably take a bit longer to reply because I'll have to build everything again. Hope this helps at least a little. J

Jerepondumie

2 years ago

Hello again, Regarding the libraries, I can't tell you much unfortunately. The problem could be caused by the library itself. Maybe a function in there that would have the same name as one of the existing ones in the program. or maybe the library using certain pins by default that my program is also using... You could try working the other way and starting the project you want to by writing the code that uses those libraries in a new program and getting that to work and then integrating the pieces of this project you want to use into the new program. That way you'll possibly see the problem appear from a different angle. And like above, if you tell me what library is troubling you, I can play with it here and see... Cheers J

Anonymous user

2 years ago

The code stops running when I add certain libraries as well

Anonymous user

7 years ago

Hi, I am trying to replicate this project and have everything connected to the breadboard and have implemented the code and I cannot get the lights to flash or anything to work. Any help would be greatly appreciated.

Jerepondumie

2 years ago

Hi Zha1997, There is a 3 second delay at the start, during which it looks like the Arduino is doing nothing. Because it is indeed doing nothing. After that, you should hear the beeps of the speaker at least. If the speaker is silent too, the batteries could be flat or the Arduino could be dead. (To test that, you can just load the Blink demo and check that the onboard LED flashes, then reload the program for this project when you're happy your Arduino isn't dead) Not being in front of your circuit, the only problem that I can think of is that the LEDs might have been plugged in the wrong way around. Make sure that the anode (long leg) of the LEDs are all on the side of the resistor in the board. If that doesn't help, re-look at your wiring and make sure that everything is connected properly, and to the correct column in the breadboard. My most common error with these breadboards is to plug the pin of a resistor in a column and the pin of the next component in the circuit in the hole next to it, in the next column. It looks right, but it isn't :) In your check, ensure that all the black wires (on the diagram) are connected to the same row of the board and all the red ones to the other row. I hope this puts you on your way to debugging your circuit. Good luck

TwoPilots

7 years ago

How do we make the player response wait time longer? I tried changing the first line to a greater number and it didn't change. Can you please help me with that? But overall, this is a fun game!

Jerepondumie

2 years ago

Hi TwoPilots, You changed the right line. For a noticeable difference, you will need to change it in 1000 increment, so 3000 = 3 seconds, 4000 = 4 seconds, etc... Glad you like the project. Have fun!

TwoPilots

2 years ago

Oh Ok. Thanks!