Understood but have you been able to find a circuit to add to the Hall sensor that converts the signal to 5V logic pulses or do you already have that added. SW is not my forte but it certainly sounds like your problem is your pulse counting code. First of all , although I am not really a SW person, the thing that jumps out at me is your whole program revolves around serial and you are only running at 9600. Serial communication has a high timing overhead. I would immediately change your speed to 115200 bps. Also, as a diagnostic test, I would comment out EVERYTHING except the pulse counting code and the serial output of the pulse count and drive the actuator using the rocker switch (disconnect it from the motor shield). Then press the rocker switch and watch the pulse count to see if it is vastly different and more accurate. If you can drive it back and forth manually and see accurate pulse counts without the software hanging then that would tell you that it is indeed a SW issue , specifically related to timing issues. Troubleshooting is all about isolating one system or code block from another by eliminating everything except one and running each block with all the others commented out. Similarly, electronics troubleshooting is about disconnect all the circuits but one and testing them all independently. Right now you have too many things going on. You need to isolate the problem by eliminating everything but one item at a time. Works for me. I'm an electronics tech.