Problem with relay

Not yet, but are you sure this is the correct place to add it? Shouldn’t it be added between + and - wires going to the pump?

You stated that the problem does not occur when you set the pin low and the motor is running. So it must have something to do with the relay contacts opening and closing when connected to the motor. The diode will prevent excessive arcing (sparks) across the relay contacts when they open or bounce. The arcing may be causing interference with the Arduino causing it to reset.

I have only 1N4148, will it be enough?

That should be OK for a small motor.
Make sure you get the polarity right. The cathode (end with the band) connects to the contact that goes to the battery

It still doesn't work, it turns off immediately
431438963_7637901802886979_6861372239803367082_n-ezgif.com-cut

Well let's eliminate the breadboard. Sometimes they have bad and intermittent connections.
Connect the RED wire from the battery directly to the relay screw terminal.
Connect the BLACK wire from the battery directly to the pump.

The diode should be connected across the pump terminals with cathode (end with black band) connected to + and other end to - (negative).

I have tried it like few minutes ago and it is not working perfectly, but works better (like 5 out of 10 times instead of 0).

How is the Arduino powered?

USB from computer

Is the relay opto isolated?

Did you eliminate the breadboard?
With the diode across the relay.

It is not

I eliminated the breadboard with both diodes and it is also like 50% success rate

Could be problem but if diode is installed and working correctly, should not.

Do you have another relay or an NPN transistor? Maybe the diode on the relay module is bad.

I don't have other relay but I will buy one with opto isolation tomorrow. I have an NPN transistor. What do you think about adding another diode in the circuit which powers the relay?

Well let' see if the Arduino is actually resetting
Try this code
Set the serial monitor to 9600

#define pompa 5

void setup() {
  pinMode (LED_BUILTIN, OUTPUT);
  pinMode(pompa, OUTPUT);
  digitalWrite(pompa, HIGH);
  Serial.begin(9600);
  Serial.println("**RESET**");
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  digitalWrite(pompa, HIGH);
  delay(2000);           
  digitalWrite(LED_BUILTIN, LOW);
  digitalWrite(pompa, LOW);
  delay(2000);
}

it is
image

So it's EMI from the relay/motor
Move the pump and relay as far away from the Arduino as the wires will reach an put something metal between them
See what happens