Hi. here use my code:
using the V0 to disable and enable the alarm
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "xxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxx";
char server[] = "xxx.xxx.xxx.xxx";
#define ledPin 12
#define pirPin 14
int pirState;
int val;
int x;
SimpleTimer timer;
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0);
}
BLYNK_WRITE(V0){
x = param.asInt();
}
void PIRval(){
val = digitalRead(pirPin);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
void pir(){
if (x == 1){
if (digitalRead(pirPin) == HIGH){
Blynk.notify("ALARM!!!");
}
}
}
void setup(){
Blynk.begin (auth, ssid, pass, server, 8080);//local server
// You can change server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
timer.setInterval(1000L, PIRval);
timer.setInterval(1000L, pir);
}
void loop(){
Blynk.run();
timer.run();
}