Hello Im currently implementing synchphysicalbutton.ino and running into issues with the toggle switch override. I can successfully maneuver the pins via esp8266 and blynk button but not the physical switch itself.
I can’t really tell where the pink wires from the switch are connected to on your ESP01, but I’m assuming they are connected to one of the top three inboard pins, which are GPIO 3, 0 or 2 respectively.
In the code, btnPin is defined as GPIO 8, which isn’t accessible on the ESP01, so you’ll need to change the code to reference the pin you’ve actually used (I’d avoid GPIO 0 if I were you).
Hopefully the voltage regulator, which is shown as 5v in your diagram is actually a 3.3v output, as ESP01s aren’t 5v tolerant.
Just an observation: I don’t know if ESP-boards has INPUT_PULLUP on their GPIO’s. So you could remove either that form the code or the external resistor
Can’t tell if the button itself is NO or NC. It should be NO (normally open) and when pushed to GND sets the input pin to LOW.
// Set your LED and physical button pins here, D4 is onboard, D5 is GPIO14, D7 is GPIO13
const int ledPin = 14;
const int btnPin = 12;
const int ledPin1 = 13;
const int btnPin1 = 15;
//BlynkTimer timer;
void checkPhysicalButton();
int ledState = LOW;
int btnState = HIGH;
int ledState1 = LOW;
int btnState1 = HIGH;
// Every time we connect to the cloud...
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(V2);
// Alternatively, you could override server state using:
//Blynk.virtualWrite(V2, ledState);
}
// When App button is pushed - switch the state
BLYNK_WRITE(V2) {
ledState = param.asInt();
digitalWrite(ledPin, ledState);
}
void checkPhysicalButton()
{
if (digitalRead(btnPin) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState != LOW) {
// Toggle LED state
ledState = !ledState;
digitalWrite(ledPin, ledState);
// Update Button Widget
Blynk.virtualWrite(V2, ledState);
}
btnState = LOW;
} else {
btnState = HIGH;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(ledPin, OUTPUT);
pinMode(btnPin, INPUT_PULLUP);
digitalWrite(ledPin, ledState);
// Setup a function to be called every 100 ms
timer.setInterval(100L, checkPhysicalButton);
}
void loop()
{
Blynk.run();
timer.run();
}