Millis() Function with Relay Connected to Motor
As Brian Drummond correctly suspected, this is an integer overflow issue.
On the ATmega Arduino, an int is a 16 bit signed type which will overflow in just over 32 seconds.
As a result, the millis() function instead returns an unsigned long which will overflow in 49.7 days.
If you change the type of &quot;timer&quot; to unsigned long then things will work in the short term.
Additionally, because you performed a subtraction before comparison, they will even work in the overflow/wraparound case, because you'll still end up with a valid time difference to compare against your threshold of 10000.
At first glance one might think that you existing code would be similarly wraparound safe, too.  But it isn't, because the math of wraparounds doesn't work right between an unsigned long and a (signed) int.
Additionally it probably has no bearing on your issue, the following line of code serves no useful purpose and should be removed:
analogWrite(7, voltage);