Detecting a PWM signal as on/off?

When the spa is on on my pool it generates a PWM signal on a 5v LED, but it's not a super stable PWM. All I want to do is be able to sense whether the spa is on or off. If I use digitalRead is sometimes reads as LOW and sometimes reads as HIGH (I assume based on which part of the PWM I happen to be polling). I experimented it pulseIn, but I couldn't get any good results, so I'm not sure I'm doing it right, I also didn't know how to deal with pulseIn when there is no signal at all when the spa is not on.

Is there an easy thing that I'm missing here?

Is there an easy thing that I'm missing here?

Record the time (millis()) when the pin is HIGH. Periodically, see how long it has been since the pin was last HIGH. Short time - the spa is on. Long time - the spa is not.

PaulS:
Record the time (millis()) when the pin is HIGH. Periodically, see how long it has been since the pin was last HIGH. Short time - the spa is on. Long time - the spa is not.

Any chance you've got a snippit of code as an example for that?

unsigned long x=0;
unsigned long y=0;

void setup() {
  // put your setup code here, to run once:
pinMode(2,INPUT);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
if(digitalRead(2) == HIGH)
{
  x=millis();
}
Serial.println("High=");
Serial.println(x);
if(digitalRead(2) == LOW)
{
  y=millis();
}
Serial.println("High=");
Serial.println(y);
delay(300);
}

This should do.

Serial.println(y);

If you want to know the length of time between the two, shouldn't you be subtracting x from y?

Delta_G:

Serial.println(y);

If you want to know the length of time between the two, shouldn't you be subtracting x from y?

As i understood he wants to know the time of the on & off this should be enough.
and if he wants the length between the two it's subtracting x from y.

I would use pulseIn to measure the pwm signal.

On timeout there is no spa running.

Whandall:
I would use pulseIn to measure the pwm signal.

On timeout there is no spa running.

I figured out why I was getting bad results. I thought pulseIn() was returning milliseconds, and I was trying to save the value as an int... turns out it was returning microseconds (as it clearly states on the information page), just divided the value by 1000 first and now everything works perfectly. Thanks!