Basic Code: //Auto Garden watering with moisture and light sensitivity //////////////Initialization////////////// #include //include LCD library int MoistSensePin = 0; //Designate moisture sensor analog pin to 0 int LightSensePin = 1; //Designate light sensor analog pin to 1 int Solenoid =3; //Designate solenoid control pin to 3 LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //initialize LCD pins void setup() { pinMode(Solenoid, OUTPUT); // Sets Solenoid Pin to output for sending 5v to mosfet gate pinMode(5, OUTPUT); pinMode(6, OUTPUT); Serial.begin(9600); lcd.begin(16, 4); // set up the LCD's number of columns and rows: lcd.print("-Watering Criteria-"); //Prints message in quotes } //////////Beginning of Loop //////////////////////// void loop() { float sensor = analogRead(MoistSensePin); //retrieve sensor value float light = analogRead(LightSensePin); //retrieve light sensor value delay(2000); //2 sec delay digitalWrite(5, HIGH); //Set status Led to On delay(250); //2 sec delay digitalWrite(5, LOW); //Set status Led to off lcd.setCursor(0, 1); //Setup txt to follow on the third line lcd.print("Moisture:"); lcd.setCursor(10, 1); //setup txt to follow on the first line lcd.print(sensor); //print "sensor" value to LCD delay(1000); //Delay by 1000 cycles sensor value for easier readability lcd.setCursor(0, 2); //Setup txt to follow on the third line lcd.print("Light:"); lcd.setCursor(7, 2); //Setup txt to follow on the third line lcd.print(light); //print "light" value to LCD delay(1000); //Delay by 1000 cycles light value for easier readability Serial.print("light: "); Serial.println(light); //print "light" variable output to serial monitor for diagnostics delay(1000); //Delay by 1000 cycles light value for easier readability Serial.print("moisture: "); Serial.println(sensor); //print "sensor" variable output to serial monitor for diagnostics delay(1000); //Delay by 1000 cycles sensor value for easier readability //////////beginning of the nested loop for solenoid control based on light and sensor values///////////////////// if (light>200) //initialization of loop controlled by the light value to determine day or night for plant safety { if (sensor>190) //if light is safe then ask if the moisture sensor is dry enough to start watering { lcd.setCursor(0, 4); //set starting point of text to second line of LCD lcd.print("!Active!"); //print active to diagnose if watering is determined to be needed digitalWrite(6, HIGH); //Set water status Led to On digitalWrite(3, HIGH); //if watering is needed the solenoid is set to high triggering solenoid delay(60000); //waters for 1min digitalWrite(3, LOW); } else //alternative if not dry enough for watering { digitalWrite(3,LOW); //set mosfet gate to low to disable or keep the solenoid disabled digitalWrite(6, LOW); lcd.setCursor(0, 4); //set starting text to second line of LCD lcd.print("Inactive!"); //print Inactive! to dertime of the solenoid has been disabled } } else //alternative if not dark enough for watering { digitalWrite(3,LOW); //keep the mosfet gate pin to low to maintain off status if not dark enough for watering digitalWrite(6, LOW); lcd.setCursor(0, 4); //set text position to second position lcd.print("Inactive!"); //print "Inactive!" to make aware its not dark enough and Inactive status is maintained } }