Fish Feeder on ESP32 does not connect to ThingSpeak

Frank Ashton on 22 Feb 2022 (Edited on 22 Feb 2022)
Latest activity Edit by Christopher Stapels on 22 Feb 2022

I have a fish feeder project running on an Arduino esp 32, it checks various parameter and feeds according to temperature. Unfortunately it has stopped, it no-longer talks to thingspeak and hence cannot upload data. I believe I have a free licence (according to thingspeak) I was only using 1 channel, hence 4 sufficient at this moment. How can I get it working again, ps feeding starts May!. I have googled and understand notice may have been given. Help please- relatively new to Arduino's and first project to us thingspeak. at the moment wireless communication appears more reliable.

Frank Ashton
Frank Ashton on 22 Feb 2022

enclose copy of my code- I should receive some serial feedback like Channel update successful. Run conditions are true Time remaining 5 : 37

but I have received nothing from serial and the lcd just says "feeding in:"-

#include max6675.h #include Servo.h #include LiquidCrystal_I2C.h #include BigNumbers_I2C.h #include math.h

// Thermocouple variables int thermoCsPort = 6; // CS pin on MAX6675 int thermoSoPort = 7; //SO pin of MAX6675 int thermoSckkPort = 8; // SCK pin of MAX6675 int units = 1; // Units to readout temp (0 = ˚F, 1 = ˚C) float error = 0.0; // Temperature compensation error

// Buzzer variables int buzzerPort = 9; // Buzzer port int buzzerRefillFrequency = 2000; // Buzzer tone frequency for refill alarm int buzzerRefillRepeat = 3; // Number of refill alarm tones int buzzerRefillDelay = 1000; // Delay of refill alarm tone int buzzerCloseFrequency = 1000; // Buzzer tone frequency for end of fire valve close alarm int buzzerCloseRepeat = 2; // Number of tones for end of fire valve close alarm int buzzerCloseDelay = 2000; // Delay of tone for end of fire valve close alarm

// Potentiometre variables int servoPort = 0; int potentioPort = 0;

// Device objects Servo myservo; float servoCalibration = 1.0; // modify this value so that servo is at 90° when angle is 90° (mine appears not to be calibrated) MAX6675 thermocouple(thermoSckkPort, thermoCsPort, thermoSoPort); //,units,error); LiquidCrystal_I2C lcd(0x27,20,4); BigNumbers_I2C bigNum(&lcd); // construct BigNumbers_I2C object, passing to it the name of our LCD object

// Regulation variables (Base on PID : // drawing = kP* errP + kI * errI + kD * errD // errP = consigneTemperature - temperature // errI = errP integral // errD = errP derivative int temperature = 0; float temperatureMin = 70; // under this temperature, the regulation starts an integral measure to estimate end or fire and close the valve float consigneTemperature = 180.0; // the desired temperature measured by the thermocouple float errP = 0.0; float errD = 0.0; float errI = 0.0; float errOld = 0.0; float kP = 5; // P parameter of the PID regulation float kI = .0005; // I parameter of the PID regulation float kD = 0.00005; // D parameter of the PID regulation

float refillTrigger = 5000; // refillTrigger used to notify need of a wood refill float closeTrigger = 15000; // closeTrigger used to close vlave at end of combustion

int potentio = 0; int oldPotentio = 0; float potentioMax = 1023.0; // Potentiometre calibration int potentionRelMax = 80; // Potentiometre value above which the regulator runs in automatic mode

int angle = 0; int drawing = 0; int oldDrawing = 0; float maxDrawing = 100.0; float minDrawing = 5.0; float zeroDrawing = 0.0;

String messageTmp; String messageDrw;

boolean closeBuzzer = true; boolean refillBuzzer = true;

void setup() { Serial.begin(9600); myservo.attach(10); myservo.write(0); myservo.detach(); lcd.init(); lcd.backlight(); bigNum.begin(); // set up BigNumbers Serial.println(__FILE__);

//Serial.println("Consigne="+ String(consigneTemperature) +" kP="+String(kP)+" kI="+String(kI)+ " kD="+String(kD));
//Serial.println("Temperature;Drawing");
pinMode(buzzerPort, OUTPUT);

} byte x = 0;//x & y determines position of character on screen byte y = 0;

void loop() { delay(5000); temperature = thermocouple.readCelsius(); potentio = analogRead(potentioPort);

delay(500);
if (temperature == -1) {
  Serial.println("Thermocouple Error!!"); // Temperature is -1 and there is a thermocouple error
} else {
    potentio =   (potentioMax - potentio) * 100 / potentioMax ;
    if (potentio < potentionRelMax ) {
      // Potentiometre regulation
      drawing = round(potentio * maxDrawing / 100);
      errI = 0;
      errD = 0;
      closeBuzzer = true;
      refillBuzzer = true;
      messageDrw = "Drw=" + String(round(drawing / maxDrawing * 100)) + "%"  + " <)= "  + String(round(drawing * 90 / maxDrawing)) + "" ;
    }
    else
    { 
      //  if(errI<closeTrigger && errP < 0 ){// Stop if end of combustion and temp decrease
      if (errI < closeTrigger  ) {
        // Serial.println(String(temperature)+";"+String(drawing/maxDrawing* 100)+";"+String(errP)+";"+String(errI)+";"+String(errD));
        // PID regulation
        errP = consigneTemperature - temperature;
        errI = errI + errP;
        errD = errP - errOld;
        drawing = kP * errP + kI * errI + kD * errD;
        errOld = errP;
        // Limit values to physical constraints ..
        if (drawing < minDrawing) drawing = minDrawing;
        if (drawing > maxDrawing)   drawing = maxDrawing;
        // Close end fire
        if (errI >= closeTrigger) errI = closeTrigger;
        if (temperature < temperatureMin) errI = 0;
        if (errI >= closeTrigger) drawing = zeroDrawing;
        messageDrw = "Drw=" + String(round(drawing / maxDrawing * 100)) + "%"  + " <)= "  + String(round(drawing * 90 / maxDrawing)) + "" ;
        //Refill Alarm
        if (errI > refillTrigger) {
          messageDrw = "Please refill !!" ;
          if (refillBuzzer) {
            for (int i = 0; i < buzzerRefillRepeat; i++) {
              tone(buzzerPort, buzzerRefillFrequency);
              delay(buzzerRefillDelay);
              noTone(buzzerPort);
              delay(buzzerRefillDelay);
            }
            refillBuzzer = false;
          }
          if (temperature > consigneTemperature) {
            errI = 0;
            errD = 0;
            refillBuzzer = true;
          }
        }
      }
      else {
        // Close Valve if end of combustion
        messageDrw = "Fire End.  <)= "  + String(round(drawing * 90 / maxDrawing)) + "" ;
        if (closeBuzzer) {
          for (int i = 0; i < buzzerCloseRepeat; i++) {
            tone(buzzerPort, buzzerCloseFrequency);
            delay(buzzerCloseDelay);
            noTone(buzzerPort);
            delay(buzzerCloseDelay);
          }
          closeBuzzer = false;
        }
      }
    }
    // Display message on LCD
    lcd.clear();
    lcd.setCursor(15, 0);
 lcd.print("Fire");
 bigNum.displayLargeInt(temperature, x, y, 4,false);
 lcd.setCursor(15,1);
 lcd.print("Temp"); 
 lcd.setCursor(0,2);
    messageTmp = "Temp=" + String(temperature) + "C" + "  " + " Po=" + round(potentio) + "%" ;
    lcd.print(messageTmp );
    lcd.setCursor(0, 3);
    lcd.print(messageDrw);
    // Serial Plotter
    // Serial.print(round(drawing/maxDrawing* 100));
    // Serial.print(" ");
    // Serial.println(temperature);
    // Turn servo only for 5° delta
    if ( abs(oldDrawing - drawing) > 5  ) {
      lcd.print(" x");
      delay(500);
      myservo.attach(10);
      angle =  drawing * 90 / maxDrawing * servoCalibration ;
      myservo.write(angle);
      delay(500);
      myservo.detach();
      oldPotentio = potentio;
      oldDrawing =  drawing;
    }
    delay(1500);
  }

}

Christopher Stapels
Christopher Stapels on 22 Feb 2022

I don't see anywhere in this code that you write to ThingSpeak, though I do see that you aren't using the ThingSpeak communication library . We strongly suggest using the library. If the code above is broken, I would suggest fixing that before trying to add ThingSpeak. Then, use the examples in the library to write something simple to ThingSpeak before you merge it with your code above.

Christopher Stapels
Christopher Stapels on 22 Feb 2022 (Edited on 22 Feb 2022)

Is there a way to see the serial monitor output of the esp32 device and check that is still working (or see what response you are getting from posting to ThingSpeak)? Your free license automatically renews yearly and allows up to 3 million messages per year. I assume the fish do not need to eat that often.