Arduino UNO disconnects after 30 seconds or more. Is it normal?

Hi,
I successfully installed local Blynk server on my Laptop. I tested it and it works like charm thanks to active members around here.

My problem is Arduino is disconnected after 30 to 50 seconds. My code is quite simple.

#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>

// Authentication Token
char auth[] = "602c1d4df1704896ad99ec5b56090f30";

// LEDs Module
char bluePin=4,greenPin=5,redPin=7,yellowPin=7;

// Switches Module
char sw1Pin=8,sw2Pin=9;

// Analog Module
int analogPin=0,angle=0;

// Servo Motor Shield
char pwmAPin=11, pwmBPin=10,dirAPin=12,dirBPin=13;

//Servos pwm Data
int pwmAValue,pwmBValue;

// Initialize Arduino Pins
void Init()
{
  pinMode(bluePin,OUTPUT);      //direct mapping to Blynk app
  pinMode(greenPin,OUTPUT);    //direct mapping to Blynk app
  pinMode(redPin,OUTPUT);     //direct mapping to Blynk app
  pinMode(yellowPin,OUTPUT); //direct mapping to Blynk app

  pinMode(sw1Pin,INPUT);
  pinMode(sw2Pin,INPUT);
  
  pinMode(pwmAPin,OUTPUT);
  pinMode(pwmBPin,OUTPUT);
  pinMode(dirAPin,OUTPUT);   //direct mapping to Blynk app
  pinMode(dirBPin,OUTPUT);  //direct mapping to Blynk app
}

void setup()
{
  //Initialize digital pins
  Init();  

  DebugSerial.begin(9600);
     
  // Blynk will work through Serial
  Serial.begin(9600);
  Blynk.begin(auth,Serial);
}

// PWM mapping through virtual pins
BLYNK_WRITE(V1) //Motor A Speed
{
   pwmAValue=param.asInt();
   int actualPWM=map(pwmAValue,0,100,0,255);
   analogWrite(pwmAPin,actualPWM);
}

// PWM mapping through virtual pins
BLYNK_WRITE(V2) //Motor B Speed
{
  pwmBValue=param.asInt();
  int actualPWM=map(pwmBValue,0,100,0,255);
  analogWrite(pwmBPin,actualPWM);
}

// Read analog potentiometer
BLYNK_READ(V3)
{
  int analogValue=analogRead(analogPin);
  angle=map(analogValue,0,1023,0,180);
  Blynk.virtualWrite(V3,angle);  
}


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

As you can see, nothing fancy, I followed the pattern and even tried only LEDs. Arduino disconnects in less than a minute although I’m running on local server not blynk cloud. Is there anything needed to be optimized? Thanks.

P.S: Do I have to use WDT to reset Arduino or it is another thing?

post serial log showing what you mean by “disconnects”

I’m not using debugger. Do you imply the cmd log?

How do you connect the motor? Is it even connected at this point? Because if it’s directly connected (I mean powered of course) via the UNO you could blow it up really easy :slight_smile:

You have debugserial in your code, what is that for?

Can’t you also use Blynk debugging?

We are not clarvoyants :slight_smile:

@Dave1829 I commenced with the template but didn’t use the debugger. The server is disconnecting not the Arduino code since I tested it on the cloud server with no problem. Anyway thsnks.

@Lichtsignaal I’m able to use Blynk on virtual simulation without need of having Arduino hardware at all. That is the essence of my project.

Virtual Arduino with Blynk

So maybe the issue is in your local network arrangements, not the code? Because the code looks good.

That is very interesting! I’ll go have a look at the link you provided. I currently use BlueStack to run Android on my Windows laptop (Blynk won’t run on the MacBook since the last couple app updates). Do you actually mirror the screen of your phone or is this an Android sim/virtualization thing?

How do you connect the Virtual Arduino to the network anyway? I don’t think I know what the Stream library does, is it also some sort of network thing? I only worked with ESP and ENC28J60 hardware :slight_smile:

1 Like

@Lichtsignaal @Dave1829
Apparently my problem was with Kaspersky. I made the jar app trusty with all communication with the app to be trusted (from network and firewall setting). It is now working fine.

I shared the project here

Thanks to everyone.