Arduino nano 33 iot and water pump

I have this waterpump

Mini/Micro Submersible Water Pump DC 3V - 5V Waterproof Amphibious Miniature Sucker Motor Aquarium for Arduino DIY USB | Shopee Malaysia

Connected the red wire to the D4 of the 33iot
The black wire is connected to GND

I have a temperature sensor which works fine.

i have this code

if(temperature<30){
digitalWrite(4,HIGH);
}
else{
digitalWrite(4,LOW);
}

however the water pump does not do what it's supposed to do. IT does not fire at all.

Thoughts ?
something to do with the Volts ? Needs relays ?

Hello

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
image

If we look at the documentation of your Arduino, it can provide only at most 7mA:
image

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

@cheznousnazrin I had to poke around a bit, to what @Anthony_P refers are "code tags".

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

wikipedia on hysteresis

It shows up all over the place in all sorts of engineering.

a7

Yeah I'm sorry :sweat_smile:
Since I'm French sometimes I use French-word in my post but in my head it sounds great... :grimacing:

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)