First of all, pls use balise code when you post some codes or monitor output (edit your post pls)
According to the websit you gave, the water pump consume at least 100mA
If we look at the documentation of your Arduino, it can provide only at most 7mA:
So you defenitly need to put a relay to command your pump
BTW, I suggest you to do something like that:
if(temperature<30){
digitalWrite(4,HIGH);
}
else if (temperature>40){
digitalWrite(4,LOW);
}
This code will start you pump when temperature is under 30, and stop ip when it is above 40
Why do this? Because in your case, as soon as it goes under 30, the pump will start. But the transition of the temperature might be slow, so one sec is gonna be under 30, and the one after maybe temperature will be 31 and so on until it's stable
And changing that fast the state of your relay will break it
The easiest is to copy your entire sketch, then come back here and use the <CODE/> tool in the message composition window tool bar and paste your code where it tells you to, you'll see
type or paste code here
You might want to first use the Autoformat tool in the IDE to,place your code in a commonly used style.
Both those greatly increase the attention your code will receive.
@Anthony_P's other suggestion is a good one. The concept is called hysteresis in control systems, you experience it without perhaps knowing when your thermostat only turns on the heat when it's gotten cold enough, one temperature, and turns it off when it's warm enough, a different, higher, threshold.
Read about it at the beach, if reading this kinda stuff at the beach is your thing
Like in computers for example!
The fan turn on at a temperature T1, and turn off once the temperature went under T2, with obviously T2<T1
(it doesn't really turn off but the speed is increased or decreased)