Fish feeder amount + deep sleep interval

Hi all,

I am working on a project with a servo controller fish feeder; I’d like to be able to set the time interval between feeding and also the amount of movements per feeding cycle via the Blynk app (V2 and V3 slider value), I cant seem to manage how to read the amount of movements and then the deep sleep time out; can someone check my script and help me out? Thanks!

/*************************************************************

  Rotate a servo using a slider!

  App project setup:
    Slider widget (0...180) on V3
 *************************************************************/

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID           "TMPLc1QkS5Mj"
#define BLYNK_DEVICE_NAME           "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "glCMTbwumW-H3I_HlyfPweDDRItCiXkK"


// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ZiggoECAA631";
char pass[] = "Broezdevries121";

Servo servo;

BLYNK_CONNECTED(){
Blynk.syncAll() ;
int pinValue;
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);}

 BLYNK_WRITE(V3)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("Aantal voeren is: ");
  Serial.println(pinValue);
  if (pinValue == 1) {
 servo.write(0);
 delay(5000);
 servo.write(180);
 delay(2000);
 servo.write(0);
 delay(20000);}
   if (pinValue == 2) {
 servo.write(0);
 delay(5000);
 servo.write(180);
 delay(2000);
 servo.write(0);
 delay(5000);
 servo.write(180);
 delay(2000);
 servo.write(0);
 delay(20000);}
    if (pinValue == 3) {
 servo.write(0);
 delay(5000);
 servo.write(180);
 delay(2000);
 servo.write(0);
 delay(5000);
 servo.write(180);
 delay(2000);
 servo.write(0);
//}
 delay(20000);}
}
 BLYNK_WRITE(V2)
{ int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
Serial.print("Sleep value is: ");
Serial.println(pinValue);
ESP.deepSleep(pinValue*10000000); // 10 second sleep


//BLYNK_WRITE(V2)
//{
// int pinValue=param.asInt();
 //Serial.print ("Time value is: ");
 //Serial.print(pinValue);
// if (pinValue == 1) {
//  servo.write(0);
//    delay(5000);
 //   servo.write(180);
 //   delay(2000);
 //   servo.write(0);
   // delay(20000);
     //Serial.print ("Time value is: ");
    // Serial.print(pinValue);
    // ESP.deepSleep(pinValue*10000000); // 10 second sleep
 //}



//}
unsigned long startTime = 0;



void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  servo.attach(2);

 

}


void loop()
{
   Blynk.run();
}

I’m pretty sure this code won’t compile, as you’re missing a closing curly bracket at the end of your BLYNK_WRITE(V2) function.

You can’t use blocking delays like this in Blynk, it won’t work.

Read this:

I’m not sure what you’re trying to achieve with this:

but it almost certainly isn’t doing what you expected.

Pete.

Hi Pete,

I am using syncvirtual to get the actual value from the server after connecting to Wifi,
the only thing I would like to achieve is to get the two values during initialisation, carry out the feeder movements and then go to deepsleep for an X amount of time (V3 in blynk app).
What am I doing wrong… I really dont get the blynktimer purpose in this script.

What you’re actually doing is saying “give me the values for all pins”
then initialising a local integer value for a variable called pinValue - which serves no purpose
Then you’re saying “give me the values for pins V2 and V3”, even you already obtained those via the syncAll.

Personally, I’ll drop the first tow lines and only request the V2 and V3 values.

If you use blocking delays then your device will disconnect from the Blynk server while BLYNK_WRITE(V3) is being executed.
If you don’t mind that then keep the delays.

Pete.

Thanks, I have deleted the first lines. After executing V3 the script does not move to the V2 script, do I need to add a command to the loop?

Actually I mean it only runs V2 and does not move to V3 because of the delay I guess? how can I change the run order?

Change the order of the sync calls!

Pete.