Hi,
Below is the wiring diagram that I have created and the code that I have written:
//include the liquid crystal library code
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
int data1 = A0; //analog pin 1
int data2 = A1; //analog pin 2
int LVL = 7; //digital input 7 is the liquid level switch
int pump = 8; //digital output pin 8 is the water pump
int valve = 9; //digital output pin 9 is the valve
int moisture =600; //set switching value for soil moisture
void setup() {
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
Serial.begin(9600); // set sample rate
lcd.begin(16,2); //set LCD screen size
lcd.clear(); //clear LCD screen
//Set analog and digital inputs and outputs
pinMode(data1, INPUT);
pinMode(data2, INPUT);
pinMode(LVL, INPUT_PULLUP);
pinMode(pump, OUTPUT);
pinMode(valve, OUTPUT);
}
void loop() {
int sensor1 = analogRead(data1); //Read sensor 1 output
int sensor2 = analogRead(data2); //Read sensor 2 output
lcd.setCursor(0,0); //Sets cursor to col 0 row 0
lcd.print("Sen1:");; //prints Sensor 1 on LCD
lcd.print(analogRead(data1)); //Prints data1 on LCD
lcd.setCursor(0,1); //Sets cursor to col 1 row 2
lcd.print("Sen2:"); //Prints Sensor2 value on LCD
lcd.print(analogRead(data2)); //Prints data2 on LCD
if((analogRead(data1)>moisture) && digitalRead(LVL)==HIGH){ //if 1st moisture sensor dry+lvl sensor high, turn on pump
digitalWrite(pump, HIGH);
digitalWrite(valve, LOW);
delay(10000);
}
if((analogRead(data2)>moisture) && digitalRead(LVL)==HIGH){ //if 2nd moisture sensor dry+lvl sensor high, turn on pump
digitalWrite(pump, HIGH);
digitalWrite(valve, LOW);
delay(10000);
}
if((analogRead(data1)>moisture) && digitalRead(LVL)==LOW){ //if 1st moisture sensor dry+lvl sensor low, open valve
digitalWrite(valve, HIGH);
digitalWrite(pump, LOW);
delay(1000);
}
if((analogRead(data2)>moisture) && digitalRead(LVL)==LOW){ //if 2nd moisture sensor dry+lvl sensor low, open valve
digitalWrite(valve, HIGH);
digitalWrite(pump, LOW);
delay(1000);
}
else{
digitalWrite(pump, LOW);
digitalWrite(valve, LOW);
delay(1000);
}
delay(1000); }
The issue that I am having is that when the level sensor that I am using prompts the pump relay to turn on, it will turn on for the desired ten seconds, however it will turn off for one second after the ten second delay, then reactive for another ten seconds. This occurs when both the moisture sensor and level switch should keep the pump on continuously. The level switch that I am using is a switch from Madison linked here: Madison Company - M8000-75 - Miniature Float Switch, PBT, 1/8" NPT, 1.13" sg, 0.75" Float Dia, M8000 Series - Allied Electronics & Automation, part of RS Group
My question is, why does the pump relay go off when it shouldn't? Thank you for the help! Please let me know if I can provide more detail about my wiring, programming, or the issue that I am having.
Thanks,
Dave