Go Down

Topic: Urgent Help with code for automating an aquaponics garden using Time/TimeAlarms (Read 924 times) previous topic - next topic

savtitan21

Hello. I am a student in high school and as a part of our senior engineering project, we have chosen to automate a garden using an arduino uno and various relays and sensors. Our goal was to control the lights and pump for a system on a timed loop using the Arduino while monitoring if these things were actually working. i have no real prior experience with any Arduino programming and nor do my 2 teammates.

Code: [Select]
/*
CODE FOR AUTOMATED AQUAPONICS SYSTEM
goals:  
 -control a pump for the tank that will be a timed loop (proposed fail-safe to prevent overflow) NOT CLOSED
 -monitor growbed water levels to ensure water is flowing through system(encorporated in proposed fail safe)
   +use filament strip water level sensor (fswls) to ensure that water is indeed in the growbed
   POSSIBLE:+relay information from the (fswls) in conjuction with the pump control code to act as fail-safe against overflow
 -control lights for plants on a closed loop system
   +check whether on or off with a photo sensor
 -display serial information on LCD

possible additions:
 -measure water quality/pH to ensure stable environment for fish
 -add resevoir of water that refills resevior tank
 -flow rate
 -temperture monitoring
 -controls for fish feeding
*/

//libraries to include
#include <LiquidCrystal.h>
#include <Time.h>
#include <Wire.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>

//pins used in LCD screen
LiquidCrystal lcd(8,9,4,5,6,7);
//sensors& readings
int lightsensorpin = A2; //analog pin #0. Defines light sensing diode
int lightReading;  //defined later as reading of light sensor
int watersensorpin = A0; // analong pin #3. Defines water sensing (fsr)
int waterReading;  //defined later as reading of water sensor
//relays
int lightsRelay = 2; // digital pin #2. Defines lights relay
int pumpRelay = 12; // digital pin #12. Defines pump relay
int start;


void setup() {

lcd.begin(16,2);
Serial.begin(9600);
digitalWrite(lightsRelay,HIGH);
pinMode(lightsRelay,OUTPUT);
Alarm.delay(3000);
digitalWrite(pumpRelay,HIGH);
pinMode(pumpRelay,OUTPUT);
Alarm.delay(3000);

//sync clock
setSyncProvider(RTC.get); //function to get the time from the RTC
if(timeStatus()!=timeSet){
Serial.println("Unable to sync with the RTC");
lcd.print("TIME NOT SET");
}
else{
Serial.println("RTC has set the system time");
lcd.print("TIME SET");
}


//WATER SCHEDULE
Alarm.alarmRepeat(8,00,0 , PumpAlarm) ; //8 AM TO 8:03AM
Alarm.alarmRepeat(11,00,0 , PumpAlarm) ; //11AM TO 11:03AM
Alarm.alarmRepeat(14,00,0 , PumpAlarm) ; //2 PM TO 2:03PM
Alarm.alarmRepeat(17,00,0 , PumpAlarm ) ; //5 PM TO 5:03PM
Alarm.alarmRepeat(20,00,0 , PumpAlarm) ; //8 PM TO 8:03PM
Alarm.alarmRepeat(23,00,0 , PumpAlarm) ; //11 PM TO 11:03PM
Alarm.alarmRepeat(2,00,0 , PumpAlarm) ; //2 AM TO 2:03AM
Alarm.alarmRepeat(5,00,0 , PumpAlarm) ; //5 AM TO 5:03AM
 
//LIGHT SCHEDULE
Alarm.alarmRepeat(8,00,0 , LightAlarm ); //8AM TO 5PM
}

void loop(){
digitalClockDisplay();
   /*---( LIGHT PORTION OF THE SKETCH )---*/
 
 
 lightReading = analogRead(lightsensorpin); // defines lightReading variable
 Serial.print("Light reading = "); //
 Serial.println(lightReading);  //Print value of light to serial monitor
  if(lightReading >= 700){    //if light value is greater than or equal to 700
  lcd.print("LIGHT IS ON");
  }
  else{
  lcd.print(Serial.print("LIGHT IS OFF"));
  }
  Alarm.delay(10000); //read for light every 10 seconds
/*--- ( WATER PORTION OF THE SKETCH )---*/

waterReading = analogRead(watersensorpin); // defines waterReading variable
 Serial.print("Water reading = ");
 Serial.println(waterReading);  //Print value of water to serial monitor
  if(waterReading <= 50){
  lcd.print("WATER IS ON");
  }
  else{
  lcd.print("WATER IS OFF");
  }
  Alarm.delay(15000); //read for light every 10 seconds
}

void digitalClockDisplay(){
// digital clock display of the time
 Serial.print(hour());
 printDigits(minute());
 printDigits(second());
 Serial.print(" ");
 Serial.print(day());
 Serial.print(" ");
 Serial.print(month());
 Serial.print(" ");
 Serial.print(year());
 Serial.println();
}

void printDigits(int digits){
 // utility function for digital clock display: prints preceding colon and leading 0
 Serial.print(":");
 if(digits < 10)
   Serial.print('0');
 Serial.print(digits);
 lcd.print(digits);
}

void PumpAlarm(){
 digitalWrite(pumpRelay, LOW);
 Alarm.delay(180000);
 Serial.println("Pump is running.");
 lcd.print("PUMP ACTIVE");  
}

void LightAlarm(){
 digitalWrite(lightsRelay, LOW); //turn lights on
 Alarm.delay(36000000);
 Serial.println("Lights are on.");
 lcd.print("LIGHTS ACTIVE");
   
}




after compiling, I ran into the error


Quote

/Applications/Arduino.app/Contents/Resources/Java/libraries/TimeAlarms/TimeAlarms.cpp: In member function 'void TimeAlarmsClass::delay(long unsigned int)':
/Applications/Arduino.app/Contents/Resources/Java/libraries/TimeAlarms/TimeAlarms.cpp:256: error: 'millis' was not declared in this scope


I have no idea what the issue was. I attempted to solve it by changing all of the delay() to Alarm.delay() to no avail. If anyone has any help that would be greatly appreciated. The deadline for this project is Dec. 17th

guix

Hello and welcome :)

Read this topic, you are using an old library that wasn't updated for the new Arduino IDE

http://arduino.cc/forum/index.php?topic=66054.45

Good luck

savtitan21

that was the solution. I can test it now. Thank you so very much

Go Up