im new to blynk
while using servo ,my connection often gets lost and connects after a while and it repeats
#include <Servo.h>
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "token";
BlynkTimer timer;
Servo myservo;
int mot_min = 90; //min servo angle (set yours)
int mot_max = 180; //Max servo angle (set yours)
int pir;
int activated =0;
/* HC-SR501 Motion Detector */
int relayInput= 7;
int LightsON = 8;
int pirValue; // Place to store read PIR Value
int pirSensor=2;
void setup()
{
Serial.begin(9600);
Blynk.begin(Serial, auth);
myservo.attach(10);
pinMode(relayInput, OUTPUT);
pinMode(LightsON, OUTPUT);
pinMode(pirSensor, INPUT);
digitalWrite(relayInput, LOW);
// myservo.write(mot_min);
//timer.setInterval(500L,getPirValue);
timer.setInterval(1000L,myTimerEvent1);
}
BLYNK_WRITE(V3) {
myservo.write(param.asInt());
if(param.asInt()==90)
{
digitalWrite(8,LOW);
activated = 0;
}
if(param.asInt()==180)
{
digitalWrite(8,HIGH);
activated = 2;
}
}
void myTimerEvent1()
{
if(activated !=2 && pir==1)
{
int sensorValue = digitalRead(pirSensor);
if(sensorValue == 1)
{
digitalWrite(relayInput,HIGH);
}
}
if(activated ==2)
{
int sensorValue = digitalRead(pirSensor);
if(sensorValue == 1)
{
digitalWrite(LightsON,HIGH);
}
}
}
void loop()
{
Blynk.run();
timer.run();
}