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