Can't run the program when I have both a soil moisture and a water pump connected to arduino uno

I have my arduino connected to a water pump that connects with a 4 aa battery case, and a water moisture sensor that is connected to a relay, which finally connects to my arduino uno. The program runs just fine when I only have the water moisture sensor connected, but when I connect the water pump to it, the program stops running. Does anyone know how I can fix this? ( The code here:)

void setup() {
  pinMode(5,OUTPUT);
  Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
void loop() {
  int val;
  val = analogRead(0); //connect sensor to Analog 0
  if (val < 270) {
    Serial.println("Wet"); //print the value to serial
    Serial.println(val); //print the value to serial
    pinMode(5,LOW);
    //delay(500);//To Soil "i", number 189
  }
  if (val > 270) {
    Serial.println("Dry"); //print the value to serial
    Serial.println(val); //print the value to serial
    pinMode(5,HIGH);
//    //delay(500);
  }
  delay(1000);
}

Welcome to the forum

Please post a schematic of your project. A 'photo of a hand drawn circuit is good enough

It will be of particular interest to see how your water pump is powered

this is about right. That black thing you see on the top right corner is that relay.

Also, I'm doing the exact same project as this. If I didn't express my project clearly, you can see here.

The pump might draw too much current and the voltage available for your arduino drops creating a crash?

Do you have a link to the relay and the pump?

1 Like

Is your battery gnd connected to the Uno gnd?

The person in that topic never got his pump to run either, so no surprise there.
Is your pump like one of these?

yes. I also have the pump connected to a small hose

No, I don't think so

Uhhhhhhhhhhhhhh... Yes.

Does the relay look like this?

Yes, but I thought that if I changed the normal relay to a photoMOS relay, it will get better. Right?

If you disconnect the pump but keep the relay connected, does the LED on the relay turn on/off when it is supposed too?

Yes

The problem is the pump.
You are not the first person to have interference problems with that particular pump.
You will need to buy a 1N4002 diode and a 0.1uF ceramic capacitor.
Connect everything like this:

1 Like

Thanks! But can you tell me the principle of this design? What are the 1N4002 diode for? And the 0.1uF ceramic capacitor?

Apparently, those pumps create a lot of electromagnetic interference (noise) that is picked up by the Arduino, the moisture sensor and all the wires connecting everything together. The noise will interfere with the operation of the moisture sensor and most analog sensors in general.

The capacitor helps to reduce the noise created by the motor when it is running. The diode helps suppress the large voltage surge created by the motor when you turn it off.
You should also make your set-up nice and tidy without wires all crisscrossing each other. Keep the motor wires away from all other wires.

How will you power the Arduino?

2 Likes

I don't
As I mentioned the problem is the pump

I've powered the Arduino with the cable, and the pump with a battery case that have 4 AA batteries inside.

I'll try to buy those things you mentioned earlier. I'll let you know if it works.
Thanks!! :blush:

You are welcome