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

Loosing connection with iOS app


#1

Hi,
I have some problems related to Blynk app in iOS (newest version) and bluetooth 4.0 HM10. I don’t have problems with starting connection etc.
I am using buttons to control DC motors but when i realease button app should stop DC motors but it doesn’t. Sometimes it stops with huuuuge delay and sometimes i have to reset my Arduino. What is the problem? Does my arduino code is bad or is not optimized?
I’d like to add that i don’t loose connection with BT module. There is some problems with connectivity between app and arduino.


#define BLYNK_PRINT Serial

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
    
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>

char auth[] = "a9eee7a0b29c4ec7ad54e1316c589471"/*token z aplikacji blynk*/;

SoftwareSerial SerialBLE(10, 11); // RX, TX

int pinValue1;
int pinValue2;
int pinValue3;
int pinValue4;

BlynkTimer timer;

void setup()
{
  Serial.begin(9600); 
  SerialBLE.begin(115200);
  Blynk.begin(SerialBLE, auth);
}

BLYNK_WRITE(V2)
{
  pinValue1 = param.asInt();

  if (pinValue1 == 1)
  {
    digitalWrite(4,HIGH);
    digitalWrite(9,HIGH);
  }
  else
  {
    digitalWrite(4,LOW);
    digitalWrite(9,LOW);
    digitalWrite(6,LOW);
    digitalWrite(8,LOW);
  }
}

BLYNK_WRITE(V3)
{
  pinValue2 = param.asInt();

  if (pinValue2 == 1)
  {
    digitalWrite(6,HIGH);
    digitalWrite(8,HIGH);
    Blynk.virtualWrite(0,0,"MOVEMENT:BACK");
  }
  else
  {
    digitalWrite(4,LOW);
    digitalWrite(9,LOW);
    digitalWrite(6,LOW);
    digitalWrite(8,LOW);
  }
}

BLYNK_WRITE(V4)
{
  pinValue3 = param.asInt();

  if(pinValue3 == 1)
  {
    digitalWrite(9,HIGH);
    digitalWrite(6,HIGH);
  }
  else
  {
    digitalWrite(4,LOW);
    digitalWrite(9,LOW);
    digitalWrite(6,LOW);
    digitalWrite(8,LOW);
  }
}

BLYNK_WRITE(V5)
{
  pinValue4 = param.asInt();

  if(pinValue4 == 1)
  {
    digitalWrite(4,HIGH);
    digitalWrite(8,HIGH);
  }
  else
  {
    digitalWrite(4,LOW);
    digitalWrite(9,LOW);
    digitalWrite(6,LOW);
    digitalWrite(8,LOW);
  }
}


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



#2

How are your Button Widgets setup… PUSH or SWITCH

The way a Button Widget works is that each time you ether press or release it (regardless of above modes) it will call the assigned BLYNK_WRITE() function… so if your button sends a HIGH signal, then the BLE connection drops, the motors have already been set to run and will keep doing so until another button action is detected setting the function LOW (and thus stopping the motors… of course resetting the device will also reset the digital pins and thus stop the motors :wink:

So you should really have it coded that the motors ONLY run when seeing a continuous loop of HIGH signals from the Buttons/Function with default settings of OFF so that in case of signal loss, the motors stop. Search this forum for keywords like Fail Safe and Rover for interesting reading :smiley:

Check out a simple control I used for my Rover… Set for WiFi, but that is just the Blynk connection, the Button logic will be the same for BLE.

EDIT - I looked at my code again and realised I never got around to implementing my own final failsafe in it :stuck_out_tongue: But basically now it would be a timed App connection check every few seconds or less, followed by an auto stop (if disconnected).

http://docs.blynk.cc/#blynk-firmware-connection-management

http://docs.blynk.cc/#blynk-firmware-virtual-pins-control-blynk_app_disconnected


#3

Doesn’t matter if I use push or switch button. When I am using push button when I push i want my motors to run but when i release this it supposed to stop motors but it doesn’t. The problem is ony when im hold button for more than 5 sec. If i hold this button about 2 or 3 secs everything works fine. And there is no drop of communication because bt is still connected to my phone. There is just huge lag. Motors stops running after few seconds and i can again push buttons but there are lags.


#4

Are you sure the baud rate of your HM-10 is set to 115200? The default is 9600

Missing pin?


#5

I deleted this line. I changed baud rate to 115200 using AT commands.


#6

Well, I I’ve uploaded your sketch on my Uno+HM10 setup and don’t experience any delays or issues.
The only things different are HM10 baud rate and the fact that I have physical leds on digital pins instead of DC motors.


#7

I had 9600 baud rate. And there also was huge delay. I’ll try this with LED diode if there is delay. I am using h-bridge to control dc motors so maybe there is problem or my hm10 is not hm10 but some kind of clone.


#8

I did some tests and I think the problem is related to power supply of dc motors. when i use 5V from arduino motors are responding well while im using the app. When i use external 9V there are some issues like i told you before.