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?