/* Aquabot Code V2.2 Last Update: 2/18/2019 Created by Grant Boone. Created to run AQUABOT, an open source garden care system to enable students to learn electronics. This code may be freely replicated, modified, distributed, and of course upgraded! Information on operation of this code may be found on Instrucatbles and the Arduino Forums. */ //Defining variables and telling the Arduino what pin each sensor is attached to int Voice = 4; //Beeper power pin int Relay4 = 8; //Relay4 = Pump int watersense = A0; //Watersense = moisture sensor int val = 0; //Reseting this value int waterset = 496; //water threshold (Change this to determine the soil saturation for each plant) int Watercheck = 5; //liquid level sensor int Pumptime = 3; //amount of time the pump runs, in seconds int Looptime = .1; //time interval between checks, in seconds int Loop = Looptime * 1000; //converting times into Arduino values int pump = Pumptime * 1000; //int light = 1; //pin to add a light sensor int reading; //this variable will count the amount of time the main loop runs //setup loop void setup() //setup code, telling the Arduino how to function during the program { Serial.begin(9600); // starts communicating with the serial monitor pinMode(Relay4, OUTPUT); // sets the Relay pin as an output pinMode(Watercheck, INPUT); // sets the liquid level sensor as an input pinMode(Voice, OUTPUT); // beeps to tell us that Aquabot is on/reset digitalWrite(Voice, HIGH); delay(500); digitalWrite(Voice, LOW); } //main loop void loop() //Runs as a series of checks and acts accordingly { int watersafe = digitalRead(Watercheck); val = analogRead(watersense); Serial.println("***********************************************"); //this is the start of the messages to the serial monitor, it reorde the readings from the sensors. Serial.println(" "); Serial.println("Water Level:"); Serial.println(" "); Serial.println(val); Serial.println(" "); Serial.println("Level Sensor Status:"); Serial.println(" "); Serial.println(watersafe); //run checks then respond if(val > waterset && watersafe == 1) { digitalWrite(Relay4, HIGH); // sets Relay #4 on //this is the case where watering happens, soil is dry, resevoir is full. Serial.println("Soil Status:"); Serial.println(" "); Serial.println("Dry"); Serial.println(" "); Serial.println("***********************************************"); Serial.println(" "); delay(pump); //runs the pump for a designated amount of time, change based on how much water you want per watering (note: 1000 is equal to 1 second) digitalWrite(Relay4, LOW); } if(val < waterset && watersafe == 0) { digitalWrite(Relay4, LOW); // sets Relay #4 on Serial.println("Soil Status:"); Serial.println(" "); Serial.println("Good"); Serial.println(" "); //soil is fine, reservoir is empty Serial.println("Please Refill Water Reservoir"); Serial.println("***********************************************"); Serial.println(" "); digitalWrite(Voice, LOW); delay(500); digitalWrite(Voice, LOW); } if(val < waterset && watersafe == 1) { digitalWrite(Relay4, LOW); // sets Relay #4 on Serial.println("Soil Status:"); Serial.println(" "); //reservoir is full, soil is good Serial.println("Good"); Serial.println(" "); Serial.println("***********************************************"); Serial.println(" "); } if(val > waterset && watersafe == 0) { digitalWrite(Relay4, LOW); // sets Relay #4 on Serial.println("Soil Status:"); Serial.println(" "); Serial.println("Dry"); Serial.println(" "); Serial.println("Please Refill Water Reservoir"); Serial.println(" "); Serial.println("***********************************************"); //soil is dry, reservoir is empty Serial.println(" "); digitalWrite(Voice, LOW); delay(500); digitalWrite(Voice, LOW); } delay(Loop); //waits a designated amount of time and then runs again }