Newbee need help with coding on NodeMCU

My project is a smart doorlock where a nodemcu would control a servo to turn, in order to turn my deadbolt on my door. I actually got this idea off of youtube, but currently, I have part of the project done, which is creating a button on my phone where when pressed, it would cause the servo to turn 90 degrees.

However, I would like add an extra part to my project, where I want to add a LED and a physical button. The function of the button is to lock/unlock the door when I don’t want to use my phone. I want to make it so when the physical button is pressed, the LED would light up for a second or two, indicating that I have pressed the button, and then turn the servo. Ideally, I would want this physical button to be synced with my button on my phone, so that when I press my physical button, the button on my phone would automatically switch and indicated the locked or unlocked status.

Currently, I have my system wired up like this (I know the board used is a Rasberry Pi, but that is the only schematic I can find online. Lets just assume its a nodemcu):

can anyone give me some help pls? Thanks in advance.

I’ll get you going in the right direction.

I’ll just assume you know the basics of blynking, if you don’t then you need to learn it, that is what the docs are for.

Basically you need a variable that tracks the state of the lock and a function that handles the locking/unlocking procedure. BlynkTimer object for handling timed events. And some other misc variables

Please note this is not a complete code, I don’t do that, you need to put in some effort yourself. This is written on a phone so some errors might exist.

Also I advice you to search this forum for @Gunner s posts regarding using servos to avoid connection problems.

Good luck!

long ledTimer = 300; // time for led blink
int ledPin =??;
int lockTimerID;
int lockBtnPin =??;
int lockState = 0; // 0 unlocked 1 locked. 
int prevLockState = 0;
BlynkTimer timer;

void handleLock() 
    // pull-down on btn
    if (digitalRead(lockBtnPin) == 1)
        // Inverse lockState if button is pressed. 
        lockState = lockState^1;
    if (prevLockState == lockState) 
       // no state change, do nothing 

   prevLockState = lockState;
   //update blynk interface 
   Blynk.virtualWrite(V1, lockState);
   // servo code 
   if (lockState == 1)

  // turn on/off lamp 4 times every x seconds
  timer.setInterval(ledTimer, blink, 4);

void blink() 
   digitalWrite(ledPin, !digitalRead(ledPin));

// add blynk button on a virtual pin 
    lockState = param.asInt();

// add lock check timer in setup 
void setup() 
   //check lockState every 300 ms. Alter at will. 
   lockTimerID = timer.setInterval(300L, handleLock);