// Libraries Available #include #include #include #include #include SoftwareSerial mySerial(1, 0); // RX, TX MyRealTimeClock myRTC(9, 8, 10); // Assign Digital Pins // Pin Definitions #define LIGHT_SENSOR A0 #define WATER_TEMP A1 #define SOIL_SENSOR A2 #define HCSR_TRIGGER 3 #define HCSR_ECHO 2 #define GROW_LIGHTS 4 #define WATER_PUMP 5 #define SPEAKER 11 // Library Objects Relay _grown_lights(GROW_LIGHTS, true); Relay _S_Pump(WATER_PUMP, true); LiquidCrystal_I2C lcd(0x27, 16, 2); UltraSonicDistanceSensor distanceSensor(HCSR_TRIGGER, HCSR_ECHO); // Trigger Pin, Echo Pin //=========================================================================== // Main Setup //=========================================================================== void setup() { myRTC.setDS1302Time(00, 45, 12, 15 , 28, 07, 2020); pinMode(11, OUTPUT); mySerial.begin(9600); _grown_lights.begin(); _grown_lights .turnOff(); _S_Pump.begin(); _S_Pump.turnOff(); lcd.init(); lcd.clear(); lcd.backlight(); LCD_PRINT("PICENG 216", "JUNIOR PROJECT"); LCD_BLINK(3, 1500); LCD_PRINT("MIXOPONICS <3", ""); LCD_BLINK(1, 3000); delay(100); lcd.clear(); } //=========================================================================== // Main Loop //=========================================================================== void loop() { mySerial.print(myRTC.hours); // Making Sure The Water Will Be Less The 7 CM High while(readDistance(true) > 15) { LCD_PRINT("NO WATER :(", ""); tone(SPEAKER, 255,250); delay(250); tone(SPEAKER, 0,250); delay(250); } // Turn Of The Tone noTone(SPEAKER); // Short Delay delay(2000); // Reading Water Temperature //if(readTemp(true) > 30) { // _S_Pump.turnOn(); // To Cool The Water Through Moving It Into the Air // } else { // _S_Pump.turnOff(); // No Need To Turn On The Pump Because The Water Temperature Is Good // } // Short Delay //delay(2000); // Reading Current Time Form RTC Module myRTC.updateTime(); mySerial.print(myRTC.hours); mySerial.print("time is: "); // LCD_PRINT(myRTC.hours ); //LCD_PRINT("time is :", String(myRTC.hours)); //delay(2000); // If Time Is Between 6am and 6pm if (myRTC.hours >= 6 && myRTC.hours <=18){ // Cheacking The Light mySerial.print("light on1: "); if(readLight(true) < 500) { mySerial.print("light on: "); _grown_lights.turnOn(); } else { _grown_lights.turnOff(); } } // Short Delay delay(250); // Make Sure The Soil Sensor Is Wet Enough while(1) { // Reading Soild Moisture int soil = readMoisture(true); // Checking The condition if(soil >= 30) { break; } else { _S_Pump.turnOn(); mySerial.print("pump on "); } } // Turn Of The Pump _S_Pump.turnOff(); // Short Delay delay(250); }