@ UKHeliBob, thanks so much for your help. I did a quick read of case instructions and changed the code as follows:
const int photoPin = 2; //byte or int for digital input???
const byte buzzerPin = 12;
byte state = 0;
unsigned long buzzerStart = 0;
unsigned long waitFiveMinsStart = 0;
unsigned long buzzerPeriod = 1000UL;
unsigned long fiveMinutePeriod = 10000UL; //changed to 10sec for testing
void setup()
{
Serial.begin(115200);// Delete?? Not required??
pinMode(buzzerPin, OUTPUT);
pinMode(photoPin, INPUT); // added to read photoPin 2
}
void loop()
{
switch (state)
{
case 0: //do nothing until the beam is broken
if (photoPin, HIGH); //adjust value or change to digitalRead if appropriate
{
state = 1;
digitalWrite(buzzerPin, HIGH); //turn on the buzzer
buzzerStart = millis();
}
break;
case 1: //buzzer sounds for one second
if (millis() - buzzerStart >= buzzerPeriod)
{
state = 2;
digitalWrite(buzzerPin, LOW); //turn off the buzzer
waitFiveMinsStart = millis();
}
// break;
case 2: //do nothing until five minutes has elapsed
if (millis() - waitFiveMinsStart >= fiveMinutePeriod)
{
state = 0;
}
// break;
}
}
It doesn't work properly I have added comments, but this looks like I am not far from achieving my goal.