Why does my pump not stop pumping?

Hi, I'm trying to use an Arduino to water my plants. As soon as the humidity sensor gives a value below 700, the pump starts pumping. But it doesnt stop, when the value goes above 700. What do i have to do differently? The comments are in German unfortunately. messwert means measurement value.

int messwert=0;                                    //Unter der Variablen "messwert" wird später der Messwert des Sensors gespeichert.

void setup() 

{ ////Hier beginnt das Setup.

  Serial.begin(9600);                               //Die Kommunikation mit dem seriellen Port wird gestartet mit einer
                                                    // Übertragungsgeschwindigkeit von 9600 Baud.
  pinMode(13,OUTPUT);                               //Setzt Digitalpin 13 als Output-Pin.

}

void loop()

{ //Hier beginnt der Hauptteil  
 messwert=analogRead(A0);                          //Die Spannung an dem Sensor wird ausgelesen und unter der Variable „messwert“ gespeichert.

  //Serial.print("Feuchtigkeits-Messwert:");         //Ausgabe am Serial-Monitor: Das Wort „Feuchtigkeits-Messwert:"

  Serial.println(messwert);                        //und im Anschluss der eigentliche Messwert.

  delay(500);                                      //Zum Schluss noch eine kurze Pause.

  if(messwert < 700)
  {
    //Serial.println(messwert);
    digitalWrite(13, HIGH);                        //Schaltet die Pumpe ein
    delay(2000);                                   //für 2 Sekunden 
    digitalWrite(13,LOW);                          //Schaltet die Pumpe wieder ab.
    delay(1000);                                   //Kurze Pause.
    messwert=analogRead(A0);                       //Überprüfen, ob die Erde feucht genug ist.
    
  } 
}

it stops after time, despite of value of messwert

According to your code, the pump should stop within 2 seconds after the humidity rises above 700.

You should post a schematic to show how you have everything wired, and links to the specifications of power supplies, pumps, sensors and other major components.

This circuit will damage your Arduino.

There is no resistor to limit the current flowing from the Arduino pin to the transistor base. You may have managed the Arduino pin, causing it to not switch off. Try another pin, but put a resistor of at least 330R.

Also there is no common ground between the power supply and the Arduino. This will cause random behaviours, or cause nothing to happen.

I had the power supply of the Arduino via the connection to the laptop. Is that actually problematic?

No, it's ok to power the Arduino separately, but there should be a common ground between the Arduino and the ground of the pump circuit.

What is the part number of your transistor?

IOR219M
3S7Y
E7303

I dont know if this MOSFET is publically available because I got it from the company I used to work in, this is a school project however.

I tried to test the theory that it just pumps for these two seconds but it doesnt tho. It just keeps on pumping until you take away the power supply of the pump.

Hi, @hankaropers

HINT; Look at your code and see if you have a statement to turn the pump OFF.

You have a statement to turn the pump on, but don't assume it will be turned OFF if the statement is not true.
You need an if statement to turn the pump off if masswert is > 700.

Tom.. :smiley: :+1: :coffee: :australia:

I have actually tried that out and it didnt work unfotunatly.

It does something new now. The pump starts pumping even if the value messwert ist above 700. I think i might have a problem with the transistor. I'm going to check it out.

Hi,

Please post your code where you tried.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Hi,

Have you got a diagram of the pinout?

Tom.. :smiley: :+1: :coffee: :australia:

No, because the pump gets turned off 2 seconds after it gets turned on. If masswert is < 700, it will get turned on for another 2 seconds next time loop() executes.

Das ist doch nix schlimmes. :nerd_face:

I could not find anything related to transistors or MOSFETS by googling for those codes.

If it is a MOSFET, then my comment about adding a resistor is less critical but still a good idea. From your diagram, I assumed it was a Base Junction Transistor rather than a MOSFET because you used the symbol for a BJT.

But my concern is that this may not be a simple MOSFET. For example it could be a Triac, which might explain why it will not switch off again. A Triac is designed for switching an AC voltage. If you use it for switching a DC voltage, it will switch on but not off again until the power is disconnected.

Try disconnecting the transistor and connect an LED (and series resistor) instead. Does the led switch on and off as expected?

Another important thing I forgot to mention in an earlier post is that you must add a flyback diode across the motor terminals, otherwise the transistor and maybe the Arduino can be damaged.

Hi,
So it seems that it would possibly be a hardware problem.

@hankaropers can you please post an image of your project?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

the onboard-LED of an arduino is connected to IO-pin 13
So this might interfere with your transistor
try a different IO-pin. for example IO-pin 12

Here is a WOKWI-simulation of your code with additional serial printing to make visible what your code is doing

You should do some extra tests.
insert a 330 Ohm resistor before the base (or gate) of the transistor
and then connect the base of transistor directly to +5V to see if this switches the pump on.

Post a datasheet of the pump or at least a picture.
Do you have a digital mutlimeter?
Do you know how to measure current?

You should measure how much current the pump is drawing.
Do you have any other transistor at hand?
This transistor that you are using look pretty unusual

best regards Stefan