Interrupt issue

Hello @jremington ,
Turning on and off of the relay and motor that is controlled by the two interrupts, one of turning on, then start counting the number of teeth once 16 got, the relay and motor should turn off.
The erratic behavior is that sometimes they turn on when the sensor gives the signal and sometime they do not.

The machine is used for weighting the rounding dough balls and it was controlled previously by siemens controller but it was damaged and I am trying to re-operate it by Arduino Mega.