[SOLVED] Water pump dosent turn off after meeting desired moisture

Hiya,
I'm new to the Arduino world so I don't know much.

Recently I've been making a smart irrigation system using Arduino Uno. The project involves in using a 4 relay module, a battery holder (holds 3 AA batteries),
a soil moisture sensor, and a water pump (3V - 6V). The system works perfectly well but when the water has reached the desired moisture, the water pump keeps on until the power is cut off.

Code:

int water; //random variable 
void setup() {
  pinMode(3,OUTPUT); //output pin for relay board, this will sent signal to the relay
  pinMode(6,INPUT); //input pin coming from soil sensor
}

void loop() { 
  water = digitalRead(6);  // reading the coming signal from the soil sensor
  if(water == HIGH) // if water level is full then cut the relay 
  {
  digitalWrite(3,LOW); // low is to cut the relay
  }
  else
  {
  digitalWrite(3,HIGH); //high to continue proving signal and water supply
  }
  delay(400); 
}

Please post a wiring diagram, and a focused, close up pic of your setup, showing the wiring.

What moisture sensor, and how does the moisture sensor "know" when the soil is "moist enough"?

It is always useful to put in a Serial.print() to see if values are what you expect them to be, for example:

water = digitalRead(6);  // reading the coming signal from the soil sensor
Serial.println(water);

Most people use an analog input to read a soil moisture sensor, which provides a range of values.

2 Likes

short:

  digitalWrite(3,!digitalRead(6)); 

turns out it cuts the relay but the battery holder is still providing electricity and therefore the water pump keeps pumping water.

Here's a photo of my setup

Do you have a wiring error?

It is hard to see from the photograph, but it looks to me as though the arduino pin 3 is connected to the input for the end relay on the PCB, but the pump wiring goes to the second relay along.

ohhh i got it now, it works thanks alot. you saved alot of time. Thanks for helping you guys!

mark as solved please!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.