I am trying to make a automatic watering system using a soil moisture sensor. When it drops below a certain point activates a pump. While showing the soil moisture on a LCD display.
So far I have managed to successfully get the LCD display working without the pump and relay connected.
I have also go the pump and relay working without the LCD display.
I have tried to combine both codes into one, it works fine until the pump is activated.
When the pump is activated the LCD has an E#R# on the bottom right hand section of the LCD and doesn't update.
Can anyone help me with the code, I think it might be something simple that I am missing seeing as I am a real amateur and self taught using google.
//#include <LiquidCrystal.h> unquote this for LCD display without I2c
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <LiquidCrystal.h>
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int j=0;
int prev=0;
int pres=0;
int motorPin = 8; // pin that turns on the motor
int blinkPin = 13; // pin that turns on the LED
int watertime = 5; // how long it will be watering (in seconds)
int waittime = 1; // how long to wait between watering (in minutes)
void setup()
{
pinMode(motorPin, OUTPUT); // set Pin 8 to an output
pinMode(blinkPin, OUTPUT); // set pin 13 to an output
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print(" Soil Moisture ");
Serial.begin(9600);
}
void loop()
{
j=analogRead(A0);
j=map(j,0,982,148,0);
pres=j;
if(j>100)
j=100;
else if(j<0)
j=0;
lcd.setCursor(6,1);
lcd.print(j);
lcd.print("% ");
Serial.println(j);
prev=j;
delay(500);
int moisturePin = analogRead(A0); //read analog value of moisture sensor
int moisture = ( 100 - ( (moisturePin / 1023.00) * 100 ) ); //convert analog value to percentage
Serial.println(moisture);
if (moisture < 40) { //change the moisture threshold level based on your calibration values
digitalWrite(motorPin, HIGH); // turn on the motor
digitalWrite(blinkPin, HIGH); // turn on the LED
delay(watertime * 1000); // multiply by 1000 to translate seconds to milliseconds
}
else {
digitalWrite(motorPin, LOW); // turn off the motor
digitalWrite(blinkPin, LOW); // turn off the LED
delay(waittime * 60000); // multiply by 60000 to translate minutes to milliseconds
}
}