I am making a home automation that turns on and off when it detects motions or when turned on by using blynk by the user. but everytime i turn on the relay it turns off after seconds, how to fix?
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int pirPin = 14;
int relayPin = 5;
int pirValue;
char auth[] = "xxxxxxxxx";
char ssid[] = "xxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxx";
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(pirPin, INPUT);
pinMode(relayPin, OUTPUT);
}
void pirSensor()
{
pirValue = digitalRead(pirPin);
Blynk.virtualWrite(V0, pirValue);
}
void loop()
{
Blynk.run();
pirSensor();
if (pirValue == HIGH)
{
digitalWrite(relayPin, LOW);
}
else
digitalWrite(relayPin, HIGH);
}