Behaviour that I cant explain

Hi Guys.

My project is behaving fairly odd and for the life of me, I cant figure out why.

First off, My Code:

int siren = 12;
int beamLed = 11;

int beam = 8; // this is a no pushbutton during the POC phase.

static unsigned long lastBeamTime = 0;

boolean alarmIsActive = false;
int sirenDuration;

void setup()
{
 pinMode (siren, OUTPUT);
 pinMode (beamLed, OUTPUT);

 pinMode (beam, INPUT);

 digitalWrite (siren, LOW);
 digitalWrite (beamLed, LOW);

 digitalWrite (beam, HIGH);
}

void loop()
{
 if (alarmIsActive && (millis() - sirenDuration) > 5000)
 {
 sirenDuration = millis();
 alarmIsActive = false;
 digitalWrite (siren, LOW);
 }
 else if (digitalRead(beamLed) == HIGH && digitalRead(beam)  == LOW && alarmIsActive && (millis() - sirenDuration) > 5000)
 {
 alarmIsActive = false;
 digitalWrite (siren, LOW);
 }

 if (digitalRead(beam) == LOW && (millis() - lastBeamTime) > 100)
 {
 lastBeamTime = millis();
 alarmIsActive = true;
 sirenDuration = millis();
 digitalWrite (siren, HIGH);
 digitalWrite (beamLed, HIGH);
 }
}

Although this is doing exactly as expected, my problem is that when it hits about the 4th cycle, the pin marked "siren", no longer responds.

Initially I thought that it could be due to debouncing, so I attemted to cater for it.
After that, I though that it could be that the leds were initially run without resistors, but that also didb't solve my issue, Now I simply don't know.

I know my code is horrible, but I'm still learning and I will sanitize it as my understanding is improved, for now, I simply want to know why the system eventually ignores the "siren" OUTPUT even though the input for it is being triggered.

Please let me know if you need any more information required that might assist in the solution for this.

PS. I get the same result on both hardware as well as simulator.

Your help and positive criticism is greatly appreciated.

Just a hobby coder here, but this might be wrong.

int sirenDuration; (and others)

sirenDuration = millis();

From the millis page:
"Note that the parameter for millis is an unsigned long, errors may be generated if a programmer tries to do math with other datatypes such as ints."
Leo..

Yup, that could be it (ie, it fails after 32.7 seconds).

Failing that, add some Serial.println() statements to tell you what's going on, so you can see what state it's getting stuck in.

Thank you.

I made a cange in the code:

int sirenDuration;
changed to
long sirenDuration = 5000;

and that seemed to solve my issue. I simulated it for 10 minutes now without issues..

Thank you guys!

Out of interest sake, How did you calculate the time in when it starts failing?

int is a range of -32,768 to **32,7**67

All variables associated with millis() should be unsigned long.

...R