Project showcase
Reaction Time Game

Reaction Time Game

This game works with sound and is made for two people. The code can easily be expanded for more people.

  • 11 views
  • 0 comments
  • 0 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
Omron b3f 1000 image 75px
SparkFun Pushbutton switch 12mm
×3
Arduino Piezo buzzer
Couldn't find single ones.
×1
Anduino Arduino Starter Kit
Not necessary, but all used parts are included, so you wouldn't have to buy all the other components up in the list.
×1

Apps and online services

About this project

First things first, I came up with the idea because of pure boredom. As you can, obviously tell from the title of the project, that it is a reaction "game". You can play it alone or with friends. The only player limit is set from the pins of the Arduino. I kept the design and wiring simple. You can use it on, I think, every Arduino Board. I posted this tiny project, because I couldn't find any similar codes. Correct me in the comments, if I'm wrong.

The Building Process

You just need some wires, a breadbord, three or more pushbuttons and a piezo. You don't even need a Resistor for grounding, because I worked with the internal INPUT_PULLUP of the Arduino.

You have to connect digital pin 3 to ground through a pushbutton. The same with pin 4 and 5.

And last but not least, you connect the piezo to ground and pin 10.

You don't have to do the exact same wiring like me, because in the code, I used integers at the begining to set the pinouts.

Now, you have a fully-functional reaction "game."

Code

ReactionGame.inoC/C++
Just paste the code into your Arduino IDE, and you're ready to go.
int tonefreq = 3000;      // adjusts your frequency for the tone() command
int untilpress;
int reset;
int Start;

unsigned long now;
unsigned long soon;
unsigned long react;
unsigned long react2; 

int playerone = 3;        // adjusts your pinouts
int playertwo = 4;
//int playerthree = 6;    // if you want to play with more players, then you have to uncomment the to slashes before playerthree, but then you have to correct more lines in the code
int resetPin = 5;
int outputPin = 10;

int upperWaitingTime = 3000;      // changes waiting time in milliseconds
int lowerWaitingTime = 7000;

void setup() {
  pinMode(outputPin,OUTPUT);
  pinMode(playerone,INPUT_PULLUP);
  pinMode(playertwo,INPUT_PULLUP);
  pinMode(resetPin,INPUT_PULLUP);
  Serial.begin(9600);
  untilpress = 0;
  
  Serial.print("Press button ");
  Serial.print(resetPin);
  Serial.println(" to start.");
  
  while(digitalRead(resetPin) == HIGH){
    
  }
  now = millis();
  soon = now + random(3000,7000);
  
}



void loop() {
  while(Start == 0){
    Serial.println("start");
    Start++;
    Serial.println("_________________________________________");
  }
  
  if(digitalRead(playerone) == LOW || digitalRead(playertwo) == LOW) {      // losing detection
  if(digitalRead(playerone) == LOW) {
  Serial.println("Left loses.");
  }

  if(digitalRead(playertwo) == LOW){
  Serial.println("Right loses.");
  
/*  if(digitalRead(playerthree) == LOW) {                             //if you want three players, then you can just delete the block comment syntax
  Serial.println("However you want to call it loses.");  
  }
*/               
  }
  
  while(digitalRead(playerone) == LOW || digitalRead(playertwo) == LOW/* || digitalRead(playerthree) == LOW*/) {     // if lost, then reset the timer, and here, too. Just delete the block comment syntax 
  now = millis();  
  soon = now + random(3000,7000);
  }                                             
  }


  
  if(soon == millis()){                       // tone
    tone(outputPin,tonefreq);
    react = millis();
    
  while(untilpress == 0){
    
  if(digitalRead(playerone) == LOW) {                   // loop until one player presses the button
    Serial.println("Left won.");
    untilpress++;
    Serial.print("Reaction time:");
    react2 = millis() - react;
    Serial.print(react2);
    Serial.println("ms");
  }

  
  if(digitalRead(playertwo) == LOW){
   Serial.println("Right has won.");
   untilpress++;
   Serial.print("Reaction time:");
   react2 = millis() - react;
   Serial.print(react2);
   Serial.println("ms");
  }

  
/*    if(digitalRead(playerthree) == LOW){            //if you want three players, then you can just delete the block comment syntax
   Serial.println("However you want to call it has won.");
   untilpress++;
   Serial.print("Reaction time:");
   react2 = millis() - react;
   Serial.print(react2);
   Serial.println("ms");
  }
*/
  }


                                                //reset after someone has won
  while(digitalRead(resetPin) == HIGH) {
    
  Start = 0;
  noTone(outputPin);
  now = millis();  
  soon = now + random(3000,7000);
  
  while(reset == 0){
    Serial.println("_________________________________");
  Serial.print("Press button ");
  Serial.print(resetPin);
  Serial.println(" to restart.");
    reset++;
    
  }
  }
  }

  untilpress = 0;
  reset = 0;
}

Comments

Similar projects you might like

2-Player Reaction Game

Project tutorial by icecreambear

  • 1,251 views
  • 0 comments
  • 4 respects

Measure your reaction time

Project tutorial by Jayraj Desai

  • 29,093 views
  • 9 comments
  • 30 respects

Arduino Pocket Game Console + A-Maze - Maze Game

Project tutorial by Alojz Jakob

  • 6,201 views
  • 7 comments
  • 18 respects

Arduino Arisoft Time Bomb Game

Project showcase by Danny van den Brande

  • 11,128 views
  • 18 comments
  • 27 respects

Arduino Game By LCD

Project tutorial by Mohammed Magdy

  • 36,402 views
  • 34 comments
  • 128 respects

LCD Game

Project showcase by Team Iron_SalsaStudio

  • 7,457 views
  • 8 comments
  • 14 respects
Add projectSign up / Login