This is my first real aruindo project and so far im having a lot of fun learning.
My current setup is an arduino nano, a soil moisture sensor and a relay connected to a 5v pump for watering my plants.
The problem I'm having is that although the led stops blinking when soil moisture reaches over "700" the relay stays on and keeps pumping water making for very wet and unhappy plants.
I'm not much of a code monkey but have the suspicion i'm using the if statements and/or the loops wrong? Any help would be greatly appreciated.
const int LED= 12;//Digital pin that the LED is connected
#define RELAY1 10 //Digial pin relay is connected too
void setup(){
Serial.begin(9600);
pinMode(LED,OUTPUT);
pinMode(RELAY1, OUTPUT);
}
void loop() {
int sensorReading= analogRead(A0); //reads the sensor value
Serial.println (sensorReading); //prints out the sensor reading
if (sensorReading > 700){//if reading is above 800, LED blinks on and off
digitalWrite(LED,HIGH); //turns the LED on
digitalWrite(RELAY1,LOW); //turns the RELAY on
delay(1000); //waits for a second
digitalWrite(LED,LOW); //turns the LED off
delay(1000); //waits for a second
if (sensorReading < 699)
digitalWrite(RELAY1,HIGH);//turns the RELAY off
}