If it all works perfectly when the pump is not connected, then electrical noise introduced by the pump is clearly to be suspected.Some things to try (it's a 12VDC pump) are to reverse a diode across the pump. Also try a separate power source for the Nano instead of sharing it with the pump (say USB cable from your PC). Anyway, post a circuit diagram showing how it is all connected up.
Still a cross-post.
Is there a way I can delete the other post?Am sorry for that..
You could ask a helpful moderator.I've already done that for you.
I tried using a different power source and it worked normally but I do have to use just one power source, any idea?
I guess that the schematic illustrates the circuit when the Arduino is powered via the USB and the pump via the 12 volt adapter. How did you wire it when you used a single power source for both ?