ESP32 (manual & app commande)

I Need some help.can anyone solve this probleme please.
ESP32 w-room (Devkit V1), I want to commande a relay manually and with app by using two pins in & out and commande in the same time to tis pin out with BLYNK APP.
the probleme here when i upload the code everythig fine except the air commande not working.
( commande manually working, with app not!)

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "***************************";
const int PushButton = 13;
const int relay = 19;

char ssid[] = "******";
char pass[] = "*********";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(relay, OUTPUT);
  pinMode(PushButton, INPUT);
}

void loop()
{
  Blynk.run();
  int Push_button_state = digitalRead(PushButton);
if ( Push_button_state == HIGH )
{ 
digitalWrite(relay, HIGH); 
}
else 
{
digitalWrite(relay, LOW); 
}
  
}```

You need to read these.

The code you have in the void loop() will not allow the app to control the digital pin. As the loop runs many (possibly thousands) of times per second, the physical switch is constantly being read, and the relay pin is going to do what the code is telling it to do.

You need to implement a timer, and a flag so that the relay pin is only changed when the state of the switch pin changes.

If you are willing to change to a button instead of the switch, there is a good example in the sketch builder.

https://examples.blynk.cc/?board=ESP32&shield=ESP32%20WiFi&example=More%2FSync%2FSyncPhysicalButton

1 Like

@Toro_Blanco
Thank you so much, it’s working :grin: