paulsb
Published © GPL3+

Reaction Timer using 3x7 segment LED displays

Times how long you take to respond to the go signal. Uses 3x7 Segment LED displays driven by 3 4026B decade counters.

BeginnerFull instructions provided1,464
Reaction Timer using 3x7 segment LED displays

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
Either a UNO or a NANO will work with this project
×1
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
Must be low current as we are connecting direct to the 4026B. I used a Multicomp Pro LS0565SRWK
×3
4026B Decade Counter
×3
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×2
Through Hole Resistor, 330 kohm
Through Hole Resistor, 330 kohm
×3
Resistor 1k ohm
Resistor 1k ohm
×2
Buzzer
Buzzer
Passive (not active) buzzer. This link does not work but any passive busser should work.
×1

Story

Read more

Schematics

Reaction Timer Schema

Code

Reaction Timer

Arduino
// Reaction Timer
// Paul Brace
// January 2021

#define START_BUTTON 2
#define REACTION_BUTTON 3
#define GET_READY_LIGHT 4
#define GO_LIGHT 5
#define BUZZER 6
#define TIME_DISPLAY 7
#define TIME_RESET 8
#define TOO_LONG 100  // Tone
#define DURATION 250  // Of tone

bool started; // True when timer running
int elapsed;  // Records the time taken in milliseconds to react 
              // will be same as time displayed on the 3 digits

void setup() {
  // Set Pins
  pinMode(START_BUTTON, INPUT_PULLUP);
  pinMode(GET_READY_LIGHT, OUTPUT);
  pinMode(GO_LIGHT, OUTPUT);
  pinMode(REACTION_BUTTON, INPUT_PULLUP);
  pinMode(TIME_DISPLAY, OUTPUT);
  pinMode(TIME_RESET, OUTPUT);
  // Flash light twice to show ready
  for (int i = 0; i < 2; i++){
    digitalWrite(GET_READY_LIGHT, HIGH);
    delay(500);
    digitalWrite(GET_READY_LIGHT, LOW);
    delay(500);
  }
  // Put into wait state
  started = false;
  ZeroTimer();
}

void ZeroTimer(){
      // This will zeroise the time displayed on the 3 digits
      digitalWrite(TIME_RESET, HIGH);
      delay(10);
      digitalWrite(TIME_RESET, LOW);
}

void WaitForStart(){
  // Will wait for the start button to be pressed
  // Note we are using PULLUP on the pin so will be HIGH by default
  // When pressed connects the pin to ground pulling it LOW
  while (started == false){
    if (digitalRead(START_BUTTON) == LOW){
      ZeroTimer();
      // Display the get ready light
      digitalWrite(GET_READY_LIGHT, HIGH);
      // Pause for a random delay between 1 and 5 seconds
      delay(random(1000, 5000));
      // Set started so will exit at end of loop
      started = true;
      //Turn out the get ready and turn on the go light 
      digitalWrite(GET_READY_LIGHT, LOW);
      digitalWrite(GO_LIGHT, HIGH);
      // Record time when start was pressed
      elapsed = millis();
      // Start the timer display
      // Output a square wave at 1000hz to record count of miliseconds
      // on the LED displays
      tone(TIME_DISPLAY, 1000);
    }
  }
}

void loop() {
  // If in wait state the wait for start to be preseed
  if (started == false){
    WaitForStart();
  }
  // Each loop check if the reaction button has been pressed
  if (digitalRead(REACTION_BUTTON) == LOW){
    // Stop the timer counting up
    noTone(TIME_DISPLAY);
    // Calculate the time it took to respond and check if greater than 999 milliseconds
    // 999 millisecionds being the maximum the 3 digits can show
    elapsed = millis() - elapsed;
    // Turn out go light
    digitalWrite(GO_LIGHT, LOW);
    // Check if took longer than 999 millisecons and, if so, sound buzzer and zero display
    if (elapsed > 999){
      ZeroTimer();
      tone(BUZZER, TOO_LONG, DURATION);
      delay(DURATION + 50);  // creates a very short pause between the tones
      tone(BUZZER, TOO_LONG, DURATION * 2);
    }
    // Go back into wait state
    // Timer will display last reaction time, if less that 999 millisconds,
    // until start pressed again
    started = false;
  }
}

Credits

paulsb
4 projects • 28 followers

Comments