watching pin state change and if stops change turns motor off

Hello all, any help would be great.

i am using

int pulsePin = 3; //motor hall effect input

how can i do a small sketech to check this is changing state and when stops changing state turns a motor off ?

so there is some pulsed signal on pin 3?
what is the frequency?

you should go IRQ based as holding state by a polled digitalRead() can miss pulses.

(code not tested)

#define THRESHOLD 500   // to be configured, now 500 millisec

boolean motorRunning = false;

volatile unsigned long lastTime = 0;

void IRQ()
{
  lastTime = millis();
}

void setup()
{
  attachInterrupt(1, IRQ, RISING);  // 1 = pin 3
}

void loop()
{
  if (millis() - lastTime > THRESHOLD)
  { 
    motorRunning == false;
    // motorStop();
  }
  else 
  {
    if (motorRunning == false)
    { 
      motorRunning = true;
      // MotorStart();
    }
  }
}

Note for safety I propose to stop the motor over and over again if there is no pulse. This is just thinking safety.
Rob

thanks fast reply.

my pulse is 6 pulses per mm of travel ( an linerar actuator), about 9 mm travel per sec

so ! 54 pulses per second ... faster than every 25 millisecond. => THRESHOLD = 25

give it a try.