Water pump is not working

The water pump is not working properly according to the code
It should stop when the soil moisture reaches a specific number but it’s not stopping!
Please help the due date is on Sunday

How do you expect anyone to help when you only show some pictures?

What do you need more?

Start by reading this: How to get the best out of this forum - Using Arduino / Installation & Troubleshooting - Arduino Forum
Your relay appears to be connected to nothing.
Please post a schematic, even if you have to hand draw it.
Also please post your code.

// Include Libraries
#include "Arduino.h"
#include "LiquidCrystal.h"
#include "Relay.h"
#include "SoilMoisture.h"
#include "Pump.h"

// Pin Definitions

#define LCD_PIN_RS 8
#define LCD_PIN_E 7
#define LCD_PIN_DB4 2
#define LCD_PIN_DB5 3
#define LCD_PIN_DB6 4
#define LCD_PIN_DB7 6
#define RELAYMODULE_PIN_SIGNAL 9
#define SOILMOISTURE_5V_PIN_SIG A3
#define WATERPUMP_PIN_COIL1 5

#define MAXDRYNESS 5000
#define WATERPOSTDELAY 1

// Global variables and defines

// object initialization
Relay relayModule(RELAYMODULE_PIN_SIGNAL);
SoilMoisture soilMoisture_5v(SOILMOISTURE_5V_PIN_SIG);
Pump waterpump(WATERPUMP_PIN_COIL1);
void setup()
{
digitalWrite(WATERPUMP_PIN_COIL1, LOW);
pinMode(WATERPUMP_PIN_COIL1, OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);

}

void loop()
{
int moisturePin = analogRead(A3); //read analog value of moisture sensor
int moisture = ( 100 - ( (moisturePin / 1023.00) * 100 ) ); //convert analog value to percentage
Serial.print("Current moisture: ");
lcd.clear();
Serial.println(moisture);
lcd.print("surr moisture: ");
lcd.print(moisture);
delay(2000);
lcd.setCursor(0,1);
lcd.clear();

if (moisture < 40) //change the moisture threshold level based on your calibration values
{
Serial.println("Soil dry, start watering\n");
lcd.clear();
lcd.print("Soil dry");
lcd.setCursor(0,1);
delay(2000);
lcd.clear();
lcd.print("Motor is On");
lcd.setCursor(0,1);
digitalWrite(WATERPUMP_PIN_COIL1, HIGH); // turn on the motor
lcd.print("watering started");
Serial.println("watering started\n");
digitalWrite(5, HIGH);
delay(MAXDRYNESS);
digitalWrite(WATERPUMP_PIN_COIL1, LOW);
lcd.clear();
}
else
{
Serial.println("\nSoil is good\n");
Serial.println("Motor is Off\n");
lcd.print("Soil is good");
delay(3000);
lcd.clear();
lcd.print("Motor is Off");
delay(3000);
lcd.clear();
digitalWrite(WATERPUMP_PIN_COIL1,LOW);
delay(60000*WATERPOSTDELAY);
}
delay(2000);
}

For instance, the components you are using, including which ARduino you are using. A drawing of how you have all the pieces connected. How you are powering the system. Tell us how you tested the sensor and the results. Have you attempted to use Serial.print() to watch the activity of the sensor?
Paul

Please go back and see step one of my instructions if you expect help.
Did you ignore the warning that you should format your code?
Please put in effort if you expect effort from others.


Here is the connection that I followed showing all the components used

This looks like the same project that @noor803 is working on - are you paired up for this project and if so, why post separate threads?

1 Like

You need to take this down to each individual item.
Get each one working by itself, then integrate them.
You are pulling a lot of power through the board and it will not take it.
Relays and pumps should be powered independently of the board with a shared ground for signals.
Your relay need to be switched by the Arduino and the pump needs to be connected to the power through the other end of the relay.

1 Like

All the other components are working fine except for the pump and relay
I tried to follow what you said and connected the relay and pump independently to batteries and here is how it went

The pump is working consistently it’s still not following the code

Excuse my questions i’m a beginner

you might consider how the wires are connected to the relay. It looks like the pump power is running through the NC part of the relay. NC, normally closed, would be a reason why the thing does not do like you want and runs all the time. Try using the NO part of the relay, normally open. Then post a new pic of your connection.

Plead edit your code post to use code tags:

delay(2000);
lcd.setCursor(0,1);
lcd.clear();

if (moisture < 40) //change the moisture threshold level based on your calibration values
{
Serial.println("Soil dry, start watering\n");
lcd.clear();
lcd.print("Soil dry");
lcd.setCursor(0,1);
delay(2000);
lcd.clear();
lcd.print("Motor is On");
lcd.setCursor(0,1);
digitalWrite(WATERPUMP_PIN_COIL1, HIGH); // turn on the motor
lcd.print("watering started");
Serial.println("watering started\n");
digitalWrite(5, HIGH);
delay(MAXDRYNESS);
digitalWrite(WATERPUMP_PIN_COIL1, LOW);
lcd.clear();
}
else
{

Sort of like that.

Once you get the pump working you'll find that water still flows from the tank to the plant. You'll want to solve the siphon issue. I used an electrical valve to stop the siphon.

Hello
Take a piece of paper, a pencil and draw a real schematic to show how we can help.

Here is the new one with a pump connected to to the normally open part, but now the pump is not even working

I will try to post the code is you requested


// Include Libraries
#include "Arduino.h"
#include "LiquidCrystal.h"
#include "Relay.h"
#include "SoilMoisture.h"
#include "Pump.h"

// Pin Definitions

#define LCD_PIN_RS  8
#define LCD_PIN_E 7
#define LCD_PIN_DB4 2
#define LCD_PIN_DB5 3
#define LCD_PIN_DB6 4
#define LCD_PIN_DB7 6
#define RELAYMODULE_PIN_SIGNAL  9
#define SOILMOISTURE_5V_PIN_SIG A3
#define WATERPUMP_PIN_COIL1 5

#define MAXDRYNESS 5000
#define WATERPOSTDELAY 1

// Global variables and defines

// object initialization
 Relay relayModule(RELAYMODULE_PIN_SIGNAL);
SoilMoisture soilMoisture_5v(SOILMOISTURE_5V_PIN_SIG);
Pump waterpump(WATERPUMP_PIN_COIL1); 
void setup()
{ 
     digitalWrite(WATERPUMP_PIN_COIL1, LOW);
  pinMode(WATERPUMP_PIN_COIL1, OUTPUT);
  Serial.begin(9600);
     lcd.begin(16,2);
  
}

void loop()
{ 
  int moisturePin = analogRead(A3); //read analog value of moisture sensor
  int moisture = ( 100 - ( (moisturePin / 1023.00) * 100 ) ); //convert analog value to percentage
   Serial.print("Current moisture: ");
  lcd.clear();
  Serial.println(moisture);
  lcd.print("surr moisture: ");
  lcd.print(moisture);
  delay(2000);
  lcd.setCursor(0,1);
  lcd.clear();

   if (moisture < 40)  //change the moisture threshold level based on your calibration values
 {
    Serial.println("Soil dry, start watering\n");
    lcd.clear();
    lcd.print("Soil dry");
    lcd.setCursor(0,1);
    delay(2000);
    lcd.clear();
    lcd.print("Motor is On");
    lcd.setCursor(0,1);
     digitalWrite(WATERPUMP_PIN_COIL1, HIGH); // turn on the motor
    lcd.print("watering started");
    Serial.println("watering started\n");
    digitalWrite(5, HIGH);
       delay(MAXDRYNESS);
         digitalWrite(WATERPUMP_PIN_COIL1, LOW);
     lcd.clear();   
  }
 else 
   {
     Serial.println("\nSoil is good\n");
     Serial.println("Motor is Off\n");
     lcd.print("Soil is good");
     delay(3000);
     lcd.clear();
     lcd.print("Motor is Off");
     delay(3000);
     lcd.clear();
     digitalWrite(WATERPUMP_PIN_COIL1,LOW);
     delay(60000*WATERPOSTDELAY);
   }
    delay(2000);
  }

In the picture posted the wires are not connected to the relay module, why?

Two wires from the motor. Right?

One motor wire goes to GROUND, RIGHT?

One wire, power, goes from the motor to the center pin of the relay output. The power to the motor goes to the NO pin of the relay. When the relay is energized the NO pin goes closed. Power is then sent to the motor through the now closed contact of the relay.

2 Likes