99.9% of new people never ask questions about solutions they are given.
Below should be most of what's needed.
You have a chance to learn something here, if you review the sketch and don't understand the code ask for explanations on the parts you don't understand.
EDIT
Added comments:
//https://forum.arduino.cc/t/help-with-programming-a-tester/910200?u=larryd
//Tester for a UUT relay board
//********************************************************************************
//Version YY/MM/DD Description
//1.00 21/09/29 Running sketch
//
//
#define LEDon HIGH
#define LEDoff LOW
#define uutCONTACTpicked LOW //swap these to reverse
#define uutCONTACTdropped HIGH //swap these to reverse
#define CLOSED LOW
#define OPENED HIGH
#define PRESSED LOW
#define RELEASED HIGH
#define ENABLED true
#define DISABLED false
#define relayON LOW
#define relayOFF HIGH
//***************************************************************
//DISABLED = we are not in timing mode
boolean timingFlag = DISABLED;
const byte relayOperatedelay = 10; //10ms, time to allow the relays to energize
const byte heartbeatLED = 13; //[PIN 13]---[220R]---[A->|-K]---GND
const byte passLED = 12;
const byte failLED = 11;
const byte relayPin = 10;
const byte uutSwitch = 5; //+5V---[50k Internal Pullup]---PIN---[contact]---GND
const byte runSwitch = 4; //+5V---[50k Internal Pullup]---PIN---[switch]---GND
const byte resetSwitch = 3; //+5V---[50k Internal Pullup]---PIN---[switch]---GND
byte lastRunSwitchState = OPENED;
byte lastResetSwitchState = OPENED;
//timing stuff
const unsigned long lowLimit = 8 * 1000ul; //8 seconds
const unsigned long highLimit = 12 * 1000ul; //12 seconds
const unsigned long exceededLimit = 15 * 1000ul; //15 seconds
unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long uutMillis;
unsigned long resultMillis;
//***************************************************************
void setup()
{
Serial.begin(9600);
pinMode(heartbeatLED, OUTPUT);
pinMode(passLED, OUTPUT);
digitalWrite(passLED, LEDoff);
pinMode(failLED, OUTPUT);
digitalWrite(failLED, LEDoff);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, relayOFF);
pinMode(runSwitch, INPUT_PULLUP);
pinMode(resetSwitch, INPUT_PULLUP);
pinMode(uutSwitch, INPUT_PULLUP);
} //END of setup()
//***************************************************************
void loop()
{
//************************************* h e a r t b e a t T I M E R
//to see if the sketch is blocking,
//is it time to toggle the LED ?
if (millis() - heartbeatMillis >= 500)
{
//restart the TIMER
heartbeatMillis = millis();
//toggle the LED
digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
}
//************************************* c h e c k S w i t c h T I M E R
//is it time to read the switches ?
if (millis() - switchMillis >= 50)
{
//restart the TIMER
switchMillis = millis();
//go read the switches
checkSwitches();
}
//************************************* U U T T I M E R
//are we testing a relay board ?
if (timingFlag == ENABLED)
{
//*********************
//has the UUT relay contact changed ?
if (digitalRead(uutSwitch) == uutCONTACTpicked)
{
//stop the test
timingFlag = DISABLED;
//save the UUT time results
resultMillis = millis() - uutMillis;
//*************
//are we within the range limits ?
if (resultMillis >= lowLimit && resultMillis <= highLimit)
{
//test passed
digitalWrite(relayPin, relayOFF);
digitalWrite(passLED, LEDon);
}
//*************
else
{
//test failed
digitalWrite(relayPin, relayOFF);
digitalWrite(failLED, LEDon);
}
}
//*************
//have we exceed the maximum time ?
else if (millis() - uutMillis >= exceededLimit)
{
//stop the test
timingFlag = DISABLED;
//test failed
digitalWrite(relayPin, relayOFF);
digitalWrite(failLED, LEDon);
}
} //END of if (timingFlag == ENABLED)
//*************************************
//other non blocking code goes here
//*************************************
} //END of loop()
//********************************************************************************
void checkSwitches()
{
//********************************************* r u n S w i t c h
//runSwitch code
byte currentState = digitalRead(runSwitch);
//**********************
//was there a change in state ?
if (lastRunSwitchState != currentState)
{
//update to the new state
lastRunSwitchState = currentState;
//********************** C L O S E D
//if we are not currently in test mode, is this switch closed ?
if (timingFlag == DISABLED && currentState == CLOSED)
{
digitalWrite(relayPin, relayON);
//time for the relays to operate
delay(relayOperatedelay);
digitalWrite(passLED, LEDoff);
digitalWrite(failLED, LEDoff);
//start the test
timingFlag = ENABLED;
//restart the TIMER
uutMillis = millis();
}
} //END of runSwitch code
//********************************************* r e s e t S w i t c h
//resetSwitch code
currentState = digitalRead(resetSwitch);
//**********************
//was there a change in state ?
if (lastResetSwitchState != currentState)
{
//update to the new state
lastResetSwitchState = currentState;
//********************** C L O S E D
//is this switch closed ?
if (currentState == CLOSED)
{
digitalWrite(relayPin, relayOFF);
digitalWrite(passLED, LEDoff);
digitalWrite(failLED, LEDoff);
//stop the test
timingFlag = DISABLED;
}
} //END of resetSwitch code
//********************************************* o t h e r S w i t c h e s
//next switch code
//*********************************************
} //END of checkSwitches()
//********************************************************************************