My 2 Lib won't work together

hello everyone im having some difficulty with some coding...
my project involes a arduino Uno that with soil sensors,water solenoids, RTC and a ESP8266.

I want to be able to set alarms to water the garden everyday at a given time, the soil senstors judges weather to water if the soil is dry. Than the ESP8266 collects this data to send to thingSpeak.

the two codes work fine by them selfs but when i combine them one Lib is not included because i get errors saying some codes of line are not declared from that Lib.

can anyone help please?

Arduino code attached.

Final_Code_for_yr12_systems.ino (8.14 KB)

karlza01:
the two codes work fine by them selfs but when i combine them one Lib is not included because i get errors saying some codes of line are not declared from that Lib.

Please post the exact error message.

...R

Without getting into details, I'll wager the problem is with SoftwareSerial as it tends NOT to play well with other libraries. When you determine that this is in fact your problem, I'll give you a solution.

I suspect that you are just a troll.

  /* can not be all 6 o'clock because arduino is a fag. has to
  be five minutes difference. does everyday exspect Sunday */

WTF?

sory about the coding with the comment just got mad at it at one point.. i think I've figured it out though, ive got it compile but dont know if it will work. the promble was that i had a chuck of coding outside a set of brackets so i tried to put it in. It's the last bit of coding at the end.

#include <SoftwareSerial.h> //Software Serial library
#define DEBUG 1
#define DEBUG true
#include <Wire.h> // for some strange reasons, Wire.h must be included here
#include "DS1307new.h" // extension to new DS1307 Arduino library that includes weekday alarms

SoftwareSerial espSerial(2, 3); //Pin 2 and 3 act as RX and TX. Connect them to TX and RX of ESP8266

String mySSID = "TelstraDB54ED"; // WiFi SSID

String myPWD = "axgv4k4vza"; // WiFi Password

String myAPI = "203324YPH9HWHVWM"; // API Key

String myHOST = "api.thingspeak.com";

String myPORT = "80";

String myFIELD = "field1";

const int AirValue = 520; //you need to replace this value with Value_1
const int WaterValue = 260; //you need to replace this value with Value_2
int intervals = (AirValue - WaterValue)/3;
int soilMoistureValue1 = 0; //A0 HIGH BEDS
int soilMoistureValue2 = 0; //A1 LOW BEDS
int waterSensor1 = 6;
int waterSensor2 = 7;
int SVLowBed1 = 8;
int SVLowBed2 = 9;
int SVHighBed1 = 3;
int SVHighBed2 = 4;
int Q = 0;
int UVsensor = A2;

void setup() {
pinMode(SVLowBed1, OUTPUT);
pinMode(SVLowBed2, OUTPUT);
pinMode(SVHighBed1, OUTPUT);
pinMode(SVHighBed2, OUTPUT);
digitalWrite(waterSensor1, HIGH);
digitalWrite(waterSensor2, HIGH);

espSerial.begin(115200);

espData("AT+RST", 1000, DEBUG); //Reset the ESP8266 module

espData("AT+CWMODE=1", 1000, DEBUG); //Set the ESP mode as station mode

espData("AT+CWJAP=""+ mySSID +"",""+ myPWD +""", 1000, DEBUG); //Connect to WiFi network
delay(1000);

#ifdef DEBUG
// init serial communication
Serial.begin(9600);
while(!Serial) {} // for Arduino Leonardo
#endif

// uncomment line below if you explicitly want to set the time
//RTC.setRAM(timeIsSetAddress, (uint8_t *)&aspectIsNotSetToken, sizeof(uint8_t));

// check if flagged that time was already set in RTC
if (RTC.isTimeSet()) {
// OK RTCandA was properly set, so let get the time
RTC.getTime();
} else {
// only do this once to set the RTC
// this routine writes the token to the RTC NV-RAM memory for future reference
RTC.setDateTimeRTC();
}

//examples how to set alarms [alarms are defined at at 5 minute resolution]
RTC.clearAlarmNvramMemory(); // clears the DS1307 internal NVRAM to hold the alarms
RTC.listNvramMemory(); // print out the NVRAM memory values
// set alarm Mondays at 5:25,
// first parameter is day of the week (sunday = 0, monday = 1, ..., saturday = 6)
// second parameter is the hour in 24h style
// last parameter is the minutes in 5 minute resolution, i.e. 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55
RTC.setAlarm( 0, 6, 0);
RTC.listNvramMemory();
RTC.setAlarm( 1, 6, 05); // set alarm Tuesdays at 16:05
RTC.listNvramMemory();
RTC.setAlarm( 2, 6, 10); // aet alarm Wednesday at 12:10
RTC.listNvramMemory();
RTC.setAlarm( 3, 6, 15); // set alarm Thursdays at 11:25
RTC.listNvramMemory();
RTC.setAlarm( 4, 6, 20);
RTC.listNvramMemory();
RTC.setAlarm ( 5, 6, 25); // set alarm Saturdays at 20:00
RTC.listNvramMemory();
/* can not be all 6 o'clock because arduino is a fag. has to
be five minutes difference. does everyday exspect Sunday */

#ifdef DEBUG
Serial.println("DS1307 time and alarm memory module");
Serial.println("Format is "hh:mm:ss dd-mm-yyyy DDD"");

uint8_t CEST = RTC.isCETSummerTime();
Serial.print("isCETSummerTime=");
Serial.println(CEST, DEC);
Serial.println();
#endif
delay(100);

}

/**

  • main loop of the sketch
    */
    void loop()

{

/* Here, I'm using the function random(range) to send a random value to the

ThingSpeak API. You can change this value to any sensor data

so that the API will show the sensor data

*/

// VAL = analogRead(Sensor1); // Send a random number between 1 and 1000
// VAL = analogRead(Sensor2);
UVsensor = analogRead(A2);

// Serial.println(Sensor1);
//Serial.println(Sensor2);
Serial.println(UVsensor);

String sendData = "GET /update?api_key="+ myAPI +"&"+ myFIELD +"="+String(UVsensor);
espData("AT+CIPMUX=1", 1000, DEBUG); //Allow multiple connections

espData("AT+CIPSTART=0,"TCP",""+ myHOST +"","+ myPORT, 1000, DEBUG);

espData("AT+CIPSEND=0," +String(sendData.length()+4),1000,DEBUG);

espSerial.find(">");

espSerial.println(sendData);

Serial.print("Value to be sent: ");

Serial.println(UVsensor);

espData("AT+CIPCLOSE=0",1000,DEBUG);

delay(1000);

}

String espData(String command, const int timeout, boolean debug)

{

Serial.print("AT Command ==> ");

Serial.print(command);

Serial.println(" ");

String response = "";

espSerial.println(command);

long int time = millis();

while ( (time + timeout) > millis())

{

while (espSerial.available())

{

char c = espSerial.read();

response += c;

}

}

if (debug)

{

Serial.print(response);

}

return response;

RTC.getTime(); // get current time from the DS1307 RTC chip
RTC.printTime(); // print it to serial
// check if alarms need to be triggered
if (RTC.isAlarmTime())
while (Q<10) {
#ifdef DEBUG
Serial.println("Alarm time has passed!");

Serial.println("Monitor 1: ");

soilMoistureValue1 = analogRead(A0); //put Sensor insert into soil
Serial.println(soilMoistureValue1);
delay(100);

if(soilMoistureValue1 > WaterValue && soilMoistureValue1 < (WaterValue + intervals))
{
Serial.println("Very Wet");
}
else if(soilMoistureValue1 > (WaterValue + intervals) && soilMoistureValue1 < (AirValue - intervals))
{
Serial.println("Wet");
}
else if(soilMoistureValue1 < AirValue && soilMoistureValue1 > (AirValue - intervals))
{
Serial.println("Dry");
digitalWrite(SVHighBed1, HIGH);
digitalWrite(SVHighBed2, HIGH);
delay(600000);
digitalWrite(SVHighBed1, LOW);
digitalWrite(SVHighBed2, LOW);
delay(1000); // wait 1 seconds
}
Serial.println("Monitor 2: ");
soilMoistureValue2 = analogRead(A1); //put Sensor insert into soil
Serial.println(soilMoistureValue2);
delay(100);

if(soilMoistureValue2 > WaterValue && soilMoistureValue2 < (WaterValue + intervals))
{
Serial.println("Very Wet");
}
else if(soilMoistureValue2 > (WaterValue + intervals) && soilMoistureValue2 < (AirValue - intervals))
{
Serial.println("Wet");
}
else if(soilMoistureValue2 < AirValue && soilMoistureValue2 > (AirValue - intervals))
{
Serial.println("Dry");
Serial.println("turning on HighBeds");
digitalWrite(SVHighBed1, HIGH);
digitalWrite(SVHighBed2, HIGH);
delay(600000);
digitalWrite(SVHighBed1, LOW);
digitalWrite(SVHighBed2, LOW);
Serial.println("turning off HighBeds");
delay(100);
Serial.println("cycle has been run");
#endif
Q++;
}
delay(1000);

}
}

You really need to get your code inside tags. Nobody (very few) are going to try and copy your code through multiple display windows simply to make life easier for you. Read the post at the top of the forum for guidance on getting your code in tags. Otherwise, good luck.

  return response;

  RTC.getTime(); // get current time from the DS1307 RTC chip
  RTC.printTime(); // print it to serial

I hope you know that nothing in the function after the 'return' statement will be executed.

This is how your sketch should have been posted:

#include <SoftwareSerial.h>       //Software Serial library
#define DEBUG 1
#define DEBUG true
#include <Wire.h>       // for some strange reasons, Wire.h must be included here
#include "DS1307new.h"  // extension to new DS1307 Arduino library that includes weekday alarms


SoftwareSerial espSerial(2, 3);   //Pin 2 and 3 act as RX and TX. Connect them to TX and RX of ESP8266


String mySSID = "TelstraDB54ED";       // WiFi SSID
String myPWD = "axgv4k4vza"; // WiFi Password
String myAPI = "203324YPH9HWHVWM";   // API Key
String myHOST = "api.thingspeak.com";
String myPORT = "80";
String myFIELD = "field1";


const int AirValue = 520;   //you need to replace this value with Value_1
const int WaterValue = 260;  //you need to replace this value with Value_2
int intervals = (AirValue - WaterValue) / 3;
int soilMoistureValue1 = 0; //A0 HIGH BEDS
int soilMoistureValue2 = 0; //A1 LOW BEDS
int waterSensor1 = 6;
int waterSensor2 = 7;
int SVLowBed1 = 8;
int SVLowBed2 = 9;
int SVHighBed1 = 3;
int SVHighBed2 = 4;
int Q = 0;
int UVsensor = A2;


void setup()
{
  pinMode(SVLowBed1, OUTPUT);
  pinMode(SVLowBed2, OUTPUT);
  pinMode(SVHighBed1, OUTPUT);
  pinMode(SVHighBed2, OUTPUT);
  digitalWrite(waterSensor1, HIGH);
  digitalWrite(waterSensor2, HIGH);


  espSerial.begin(115200);


  espData("AT+RST", 1000, DEBUG);                      //Reset the ESP8266 module


  espData("AT+CWMODE=1", 1000, DEBUG);                 //Set the ESP mode as station mode


  espData("AT+CWJAP=\"" + mySSID + "\",\"" + myPWD + "\"", 1000, DEBUG); //Connect to WiFi network
  delay(1000);




#ifdef DEBUG
  // init serial communication
  Serial.begin(9600);
  while (!Serial) {} // for Arduino Leonardo
#endif




  // uncomment line below if you explicitly want to set the time
  //RTC.setRAM(timeIsSetAddress, (uint8_t *)&aspectIsNotSetToken, sizeof(uint8_t));


  // check if flagged that time was already set in RTC
  if (RTC.isTimeSet())
  {
    // OK RTCandA was properly set, so let get the time
    RTC.getTime();
  }
  else
  {
    // only do this once to set the RTC
    // this routine writes the token to the RTC NV-RAM memory for future reference
    RTC.setDateTimeRTC();
  }


  //examples how to set alarms [alarms are defined at at 5 minute resolution]
  RTC.clearAlarmNvramMemory(); // clears the DS1307 internal NVRAM to hold the alarms
  RTC.listNvramMemory(); // print out the NVRAM memory values
  // set alarm Mondays at 5:25,
  // first parameter is day of the week (sunday = 0, monday = 1, ..., saturday = 6)
  // second parameter is the hour in 24h style
  // last parameter is the minutes in 5 minute resolution, i.e. 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55
  RTC.setAlarm( 0, 6, 0);
  RTC.listNvramMemory();
  RTC.setAlarm( 1, 6, 05); // set alarm Tuesdays at 16:05
  RTC.listNvramMemory();
  RTC.setAlarm( 2, 6, 10); // aet alarm Wednesday at 12:10
  RTC.listNvramMemory();
  RTC.setAlarm( 3, 6, 15); // set alarm Thursdays at 11:25
  RTC.listNvramMemory();
  RTC.setAlarm( 4, 6, 20);
  RTC.listNvramMemory();
  RTC.setAlarm ( 5, 6, 25); // set alarm Saturdays at 20:00
  RTC.listNvramMemory();
  /* can not be all 6 o'clock because arduino is a fag. has to
    be five minutes difference. does everyday exspect Sunday */


#ifdef DEBUG
  Serial.println("DS1307 time and alarm memory module");
  Serial.println("Format is \"hh:mm:ss dd-mm-yyyy DDD\"");


  uint8_t CEST = RTC.isCETSummerTime();
  Serial.print("isCETSummerTime=");
  Serial.println(CEST, DEC);
  Serial.println();
#endif
  delay(100);
}


/**
  main loop of the sketch
*/
void loop()
{
  /* Here, I'm using the function random(range) to send a random value to the
    ThingSpeak API. You can change this value to any sensor data
    so that the API will show the sensor data
  */
  //  VAL = analogRead(Sensor1); // Send a random number between 1 and 1000
  //   VAL = analogRead(Sensor2);
  UVsensor = analogRead(A2);


  // Serial.println(Sensor1);
  //Serial.println(Sensor2);
  Serial.println(UVsensor);


  String sendData = "GET /update?api_key=" + myAPI + "&" + myFIELD + "=" + String(UVsensor);
  espData("AT+CIPMUX=1", 1000, DEBUG);       //Allow multiple connections


  espData("AT+CIPSTART=0,\"TCP\",\"" + myHOST + "\"," + myPORT, 1000, DEBUG);


  espData("AT+CIPSEND=0," + String(sendData.length() + 4), 1000, DEBUG);


  espSerial.find(">");


  espSerial.println(sendData);


  Serial.print("Value to be sent: ");
  Serial.println(UVsensor);
  espData("AT+CIPCLOSE=0", 1000, DEBUG);


  delay(1000);
}
String espData(String command, const int timeout, boolean debug)
{
  Serial.print("AT Command ==> ");


  Serial.print(command);


  Serial.println("     ");
  String response = "";


  espSerial.println(command);


  long int time = millis();


  while ( (time + timeout) > millis())
  {
    while (espSerial.available())
    {
      char c = espSerial.read();
      response += c;
    }
  }


  if (debug)
  {
    Serial.print(response);
  }


  return response;


  RTC.getTime(); // get current time from the DS1307 RTC chip
  RTC.printTime(); // print it to serial
  // check if alarms need to be triggered
  if (RTC.isAlarmTime())
    while (Q < 10)
    {


#ifdef DEBUG
      Serial.println("Alarm time has passed!");


      Serial.println("Monitor 1: ");


      soilMoistureValue1 = analogRead(A0);  //put Sensor insert into soil
      Serial.println(soilMoistureValue1);
      delay(100);


      if (soilMoistureValue1 > WaterValue && soilMoistureValue1 < (WaterValue + intervals))
      {
        Serial.println("Very Wet");
      }
      else if (soilMoistureValue1 > (WaterValue + intervals) && soilMoistureValue1 < (AirValue - intervals))
      {
        Serial.println("Wet");
      }
      else if (soilMoistureValue1 < AirValue && soilMoistureValue1 > (AirValue - intervals))
      {
        Serial.println("Dry");
        digitalWrite(SVHighBed1, HIGH);
        digitalWrite(SVHighBed2, HIGH);
        delay(600000);
        digitalWrite(SVHighBed1, LOW);
        digitalWrite(SVHighBed2, LOW);
        delay(1000); // wait 1 seconds
      }
      Serial.println("Monitor 2: ");
      soilMoistureValue2 = analogRead(A1);  //put Sensor insert into soil
      Serial.println(soilMoistureValue2);
      delay(100);


      if (soilMoistureValue2 > WaterValue && soilMoistureValue2 < (WaterValue + intervals))
      {
        Serial.println("Very Wet");
      }
      else if (soilMoistureValue2 > (WaterValue + intervals) && soilMoistureValue2 < (AirValue - intervals))
      {
        Serial.println("Wet");
      }
      else if (soilMoistureValue2 < AirValue && soilMoistureValue2 > (AirValue - intervals))
      {
        Serial.println("Dry");
        Serial.println("turning on HighBeds");
        digitalWrite(SVHighBed1, HIGH);
        digitalWrite(SVHighBed2, HIGH);
        delay(600000);
        digitalWrite(SVHighBed1, LOW);
        digitalWrite(SVHighBed2, LOW);
        Serial.println("turning off HighBeds");
        delay(100);
        Serial.println("cycle has been run");
#endif
        Q++;
      }
      delay(1000);


    }
}