However, despite the delay only being 200 milliseconds, the pump works continues working for more time, as shown here, and it seems as if the relay is unable to stop the pump from working.
Is there a problem with my code or am I using the wrong hardware?
[edit]This is a cross post with this thread
Don't do that.
As you can see, there's different approaches of different people trying to help you solve your problem, not knowing of the existence of the other thread.
This is not helpful and very disrespectful towards those willing to help you.[/edit]
You seem to be using some 9 volts Li-Ion battery in a 6F22 form factor.
What's the capacity of that battery ?
Is the code you're showing us all you have, or is it a snippet ?
Watching your video, i can see your on board LED (pin 13) blinking.
It seems to me it has some relation to your IR sensor (LED off is relay off).
But this might also be related to some power problem (which includes a combination of those possibilities).
So easiest thing to do, would be to power your Arduino from another source than this battery.
Just to rule out the battery is your problem.
Serial prints are a very good way to debug, as wildbill already mentioned.
Put them in some smart locations in your code and have it output clear information so you can see what's going on.
The same goes for some extra delay()s (just about the only valid reason to use delay()).
The combination will help you see what exactly goes on during your sketch.
If you don't want or can't use serial monitor, figure out a smart use of pin 13, with its on board LED.
You can remove those lines from your sketch once you know it works as desired.