Why my water pump wont turn off even though the relay is sending a signal to turn off because my soil moisture is wet

my hardware is:
SRD-12VDC-SL-C relay module
12V water pump

CODE:

#include<LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);

int sensor_pin = A0;
int relay_pin = 7;

void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.backlight();
lcd.setBacklight(HIGH);
pinMode(sensor_pin, INPUT);
pinMode(relay_pin, OUTPUT);
}

void loop()
{
int sensor_data = analogRead(sensor_pin);
Serial.print("Sensor_data:");
Serial.print(sensor_data);
Serial.print("\t | ");

if(sensor_data > 950)
{
Serial.println("No moisture, Soil is dry");
digitalWrite(relay_pin, HIGH);
lcd.setCursor(0,0);
lcd.print("Soil Dry ");
lcd.setCursor(0,1);
lcd.print("Motor ON ");
}
else if(sensor_data >= 400 && sensor_data <= 950)
{
Serial.println("There is some moisture, Soil is medium");
digitalWrite(relay_pin, LOW);
lcd.setCursor(0,0);
lcd.print("Soil Medium");
lcd.setCursor(0,1);
lcd.print("Motor OFF");
}
else if(sensor_data < 400)
{
Serial.println("Soil is wet");
digitalWrite(relay_pin, LOW);
lcd.setCursor(0,0);
lcd.print("Soil Wet ");
lcd.setCursor(0,1);
lcd.print("Motor OFF");
}

delay(100);
}

Show a drawing of your wiring.

Relays do not send signals. A signal is sent to the relay to make or break a path.

Format your code like this, using the < CODE > button in the message box...

#include<LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

int sensor_pin = A0;
int relay_pin = 7;

void setup()
{
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.backlight();
  lcd.setBacklight(HIGH);
  pinMode(sensor_pin, INPUT);
  pinMode(relay_pin, OUTPUT);
}

void loop()
{
  int sensor_data = analogRead(sensor_pin);
  Serial.print("Sensor_data:");
  Serial.print(sensor_data);
  Serial.print("\t | ");

  if (sensor_data > 950)
  {
    Serial.println("No moisture, Soil is dry");
    digitalWrite(relay_pin, HIGH);
    lcd.setCursor(0, 0);
    lcd.print("Soil Dry ");
    lcd.setCursor(0, 1);
    lcd.print("Motor ON ");
  }
  else if (sensor_data >= 400 && sensor_data <= 950)
  {
    Serial.println("There is some moisture, Soil is medium");
    digitalWrite(relay_pin, LOW);
    lcd.setCursor(0, 0);
    lcd.print("Soil Medium");
    lcd.setCursor(0, 1);
    lcd.print("Motor OFF");
  }
  else if (sensor_data < 400)
  {
    Serial.println("Soil is wet");
    digitalWrite(relay_pin, LOW);
    lcd.setCursor(0, 0);
    lcd.print("Soil Wet ");
    lcd.setCursor(0, 1);
    lcd.print("Motor OFF");
  }

  delay(100);
}

Your code works in a simulation (red arrow showing relay ON... then the relay turns off at another setting)
relay

And the part number for your relay.

I would like to recommend you follow the below debugging process to find out the source of issue:

  • Connect your pump directly to the power source to check if the problem is on the pump or not.
  • If the pump works, connect your pump to the relay, and test if the relay can control the pump or not.
  • If the relay works, connect the pump to Arduino via relay and try the simplest code in the Arduino control pump tutorial to make sure that your wiring is correct.
  • If it works, try the simple code that uses the soil moisture sensor controls pump.
  • If it works, add LCD and test

connecting your pump

Sounds like the relay contacts are sticking. Do you have a kickback suppression diode across the pump leads? If the indicator LED on the relay module goes OFF, but the pump still runs, tap the top of the relay with a small screwdriver handle and see if it releases.

hey guys now my relay module is sending turning green always and it keeps the pump on but my soil moisture sensor is high enough that it should turn off the pump but it stays on

What did you change in your program or hardware?

Does the green LED indicate the the relay module is powered or that the relay is activated? Please post the relay's datasheet or it's brand name and exact part number or the web page of the place where you bought it.

What is the pump's rated current or wattage?

Hi, @kodexski
Welcome to the forum.

Can you please post some images of your project?
So we can see your component layout.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

What are you using as a power supply for the pump?

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

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