BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

When pressing V0 button connection is lost


#1

Dear All, I’m new to arduino and to Blynk.
But I’m trying to build a simple project. In Blynk I use only two buttons connected to virtual ports V0 and V1.
I’m using arduino MKR1000 and on V1 i have connected a servo motor, On V0 I have just a small submergable pump (3V) connected with a transistor to MKR1000.
Now my problem. when I press button V1 on Blynk the servo does what he need to do.
But when pressing Button V0 the pump starts, and blynk loses his connection, and the pump works on without to stop even when the program is in the MKR1000 to stop it,
What am I doing wrong?

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleMKR1000.h>
#include "Servo.h"

Servo servo;  // kreiramo servo objekt za upravljanje motorom
int pos = 0;    // varijabla u koju spremamo trenutnu poziciju motora
int pinValue;// Varijabla za dugme iz Blynka).
int pinValue0;// Varijabla za dugme iz Blynka).
char auth[] = "19aebd4f72494940bcc82808d303fc21";// You should get Auth Token in the Blynk App.
char ssid[] = "AndroidAP";// Your WiFi credentials.
char pass[] = "3042311471"; // Set password to "" for open networks.

BLYNK_WRITE(V0){ //starts when V0 is pressed
   int pinValue0 = param.asInt();//copy virtual pin to pinValue
    
    digitalWrite(9, HIGH);  // start pump on pin 9
    delay(5000);            // wait 5 seconds
    digitalWrite(9, LOW);   // stop pump
}
BLYNK_WRITE(V1){ //servo

  int pinValue = param.asInt();//copy virtual pin state
  if (pinValue == HIGH) {
    servo.attach(8);// connects servo to D8
      for (pos = 0; pos <= 70; pos += 1) { // goes from 0 degrees to 70 degrees in steps of 1 degree
      servo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);  // waits 15ms for the servo to reach the position
   
  }
  delay (1000);//delay between open and close
      for (pos = 70; pos >= 0; pos -= 1) { // goes from 70 degrees to 0 degrees
      servo.attach(8);
      servo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
   
  } 
  servo.detach();
}  }

void setup()
{
  Serial.begin(9600);
  servo.write(0);
  Blynk.begin(auth, ssid, pass);
  pinMode(9, OUTPUT);
}

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


#2

That is correct. The Delay() causes your connection loss most likeley.


#3

You mean the delay to wait 5 seconds? but I have also a delay of 1 second on V1 for the servo why doesn’t it lose connection then, it loses only for V0

BLYNK_WRITE(V0){ //starts when V0 is pressed
int pinValue0 = param.asInt();//copy virtual pin to pinValue

digitalWrite(9, HIGH);  // start pump on pin 9
delay(5000);            // wait 5 seconds
digitalWrite(9, LOW);   // stop pump

#4

It’s probably just too much. Try limiting it to 1s and see what happens. Or remove it all together to see if that is really the problem. Small effort and you can probably see quite quick if that is a solution :slight_smile:


#5

@antoniomidnight better use timers :wink:


#6

Thank you I will try it when I get home. If this will solve the connection problem, how should i write then the code? I have set now to wait 5 second just to see if this works, but at the end I propably need to wait about 20 seconds. This project should be a food feeder for anymals and with this pump I supply water to the anymal, and it take about 20 second to fill enough water.


#7

Delay stops ALL processing… and Blynk times out and disconnects.

Use timers instead… A timeout timer that stops the pump would work nicely.

http://docs.blynk.cc/#blynk-firmware-blynktimer

https://playground.arduino.cc/Code/SimpleTimer#Functions


#8

Thanks a lot, i will try it


#9

just to be complete: most electronics, like arduino, have watch dog timers (WDT) usually 2 one software and one hardware, timers differ but again usually software around 3s and hardware around 5 seconds. If these timers don’t get reset within that amount of time: they reset the module. (as they think that the module has either frozen/crashes/ended up in in an endless loop).