Hello everyone. I apologize in advance for my English, I write with the help of a translator))) Lighting system in the house, 2 lamps, 2 channel relay, 2 switches, relay power separately, controller power separately. Faced with the problem of false positives. The problem is the following, I connect the entire system, flash Nodemcu, everything works. But after some time, Nodemcu switches the relay itself, this can happen in 5 minutes, maybe in 1 hour. But the funny thing is, the whole system works fine during the day (2-3 false positives), and at night it goes crazy. Help me solve the problem. BLINK server, installed the latest library update.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define AUTH "04-ZbCvNAAfdfR1bN1RqLcixxmcQ1D7J" // You should get Auth Token in the Blynk App.
#define WIFI_SSID "MTSRouter-436FFB" //Enter Wifi Name MTSRouter-436FFB
#define WIFI_PASS "52848315" //Enter wifi Password 52848315
#define RELAY_PIN_3 D1 // ΠΏΠΈΠ½ ΠΊ ΠΊΠΎΡΠΎΡΠΎΠΌΡ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌ ΡΠ΅Π»Π΅
#define RELAY_PIN_4 D5
#define PUSH_BUTTON_3 D7 // ΠΏΠΈΠ½ ΠΊ ΠΊΠΎΡΠΎΡΠΎΠΌΡ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌ Π²ΡΠΊΠ»ΡΡΠ°ΡΠ΅Π»Ρ/ΠΊΠ½ΠΎΠΏΠΊΠ°
#define PUSH_BUTTON_4 D6 //
#define VPIN_BUTTON_3 V4 // Π²ΠΈΡΡΡΠ°Π»ΡΠ½ΡΠΉ ΠΏΠΈΠ½ Π² ΠΠΠΠΠ ΠΊ ΠΊΠΎΡΠΎΡΠΎΠΌΡ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌ Π²ΡΠΊΠ»ΡΡΠ°ΡΠ΅Π»Ρ/ΠΊΠ½ΠΎΠΏΠΊΠ°
#define VPIN_BUTTON_4 V5
BlynkTimer timer;
void checkPhysicalButton();
int relay1State = LOW; //ΡΡΡ Π΄ΠΎΠ±Π°Π²Π»ΡΠ΅ΠΌ ΠΏΠΎ Π°Π½Π°Π»ΠΎΠ³ΠΈΠΈ ΡΠ΅Π»Π΅ 1,2,3 ΠΈ Ρ.Π΄.
int pushButton1State = HIGH; //ΡΡΡ Π΄ΠΎΠ±Π°Π²Π»ΡΠ΅ΠΌ ΠΏΠΎ Π°Π½Π°Π»ΠΎΠ³ΠΈΠΈ Π²ΡΠΊΠ»ΡΡΠ°ΡΠ΅Π»Ρ/ΠΊΠ½ΠΎΠΏΠΊΡ 1,2,3 ΠΈ Ρ.Π΄.
int relay2State = LOW;
int pushButton2State = HIGH;
int relay3State = LOW;
int pushButton3State = HIGH;
int relay4State = LOW;
int pushButton4State = HIGH;
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(VPIN_BUTTON_3);
Blynk.syncVirtual(VPIN_BUTTON_4);
// Alternatively, you could override server state using:
// Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
// Blynk.virtualWrite(VPIN_BUTTON_2, relay2State);
// Blynk.virtualWrite(VPIN_BUTTON_3, relay3State);
// Blynk.virtualWrite(VPIN_BUTTON_4, relay4State);
}
// When App button is pushed - switch the state
BLYNK_WRITE(VPIN_BUTTON_3) {
relay3State = param.asInt();
digitalWrite(RELAY_PIN_3, relay3State);
}
BLYNK_WRITE(VPIN_BUTTON_4) {
relay4State = param.asInt();
digitalWrite(RELAY_PIN_4, relay4State);
}
void checkPhysicalButton()
{
if (digitalRead(PUSH_BUTTON_3) == LOW) {
// pushButton3State is used to avoid sequential toggles
if (pushButton3State != LOW) {
// Toggle Relay state
relay3State = !relay3State;
digitalWrite(RELAY_PIN_3, relay3State);
// Update Button Widget
Blynk.virtualWrite(VPIN_BUTTON_3, relay3State);
}
pushButton3State = LOW;
} else {
pushButton3State = HIGH;
}
if (digitalRead(PUSH_BUTTON_4) == LOW) {
// pushButton4State is used to avoid sequential toggles
if (pushButton4State != LOW) {
// Toggle Relay state
relay4State = !relay4State;
digitalWrite(RELAY_PIN_4, relay4State);
// Update Button Widget
Blynk.virtualWrite(VPIN_BUTTON_4, relay4State);
}
pushButton4State = LOW;
} else {
pushButton4State = HIGH;
}
}
void setup()
{
Serial.begin(115200);
Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS,"blynk-cloud.com");
pinMode(RELAY_PIN_3, OUTPUT);
pinMode(PUSH_BUTTON_3, INPUT_PULLUP);
digitalWrite(RELAY_PIN_3, relay3State);
pinMode(RELAY_PIN_4, OUTPUT);
pinMode(PUSH_BUTTON_4, INPUT_PULLUP);
digitalWrite(RELAY_PIN_4, relay4State);
// Setup a function to be called every 100 ms
timer.setInterval(100L, checkPhysicalButton);//
}
void loop()
{
Blynk.run();
timer.run();
}
```cpp
void loop()