Having trouble with Nodemcu programming, first time with Blynk

Hi, I’m a beginner in arduino and nodemcu and i really need help for a one time project. Currently i am making a door alarm system with a nodemcu ch340, a magnetic reed switch and a breadboard. Currently, setting up the physical system has been successful and i have connected the nodemcu D1 and GND to the reed switches with the aid of a metal strip i took from a breadboard.

!These are the pictures of my system. Currently i do know that the code is working in the sense that the blynk app on my phone states that it is connected to the nodemcu, however there seems to be a probelm as the code is not doing anything at all. Here is the code:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
char auth[] = "Ta4zCjD2hhmo6mFeRViHofXvNE7oLQK8"; //eg8NNwEGGw04hU8Me9onpBci_SL50Wvp
char ssid[] = "yoon"; //yoon
char pass[] = "Jangyong123$"; //Jangyong1234$
int flag = 0;

void notifyOnButtonPress()
  int isButtonPressed = digitalRead(D1);
  if (isButtonPressed == 1 && flag == 0) {
    Serial.println("The door has been opened");
    Blynk.notify("Alert : The door has been opened");
    Blynk.virtualWrite(V0, "OPEN");
    flag = 1;
  else if (isButtonPressed == 0)
    Blynk.virtualWrite(V0, "CLOSE");
    flag = 0;
void setup()
  Blynk.begin(auth, ssid, pass);
  pinMode(D1, INPUT_PULLUP);
  timer.setInterval(16000L, notifyOnButtonPress);
void loop()

Whenever i upload this code, nothing ever happens and it is very weird. Would it be fine if someone could help me for this? Thank you very much!

@YoonSaeYoung please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:


Thank you very much

What does your serial monitor show?


Not sure but if your reed switch is closed for less than 16 seconds, that can’t work :thinking:
Better use interrupts instead of timer , or just try 1000L instead of 16000

1 Like

Thanks so much!!!

1 Like

Hi, my first time with arduino for a one time project so i don’t know what it is, but i’ll quickly go learn about it and get back to you

1 Like

Sorry but this doesn’t work :frowning:

What do you see on your serial monitor if you add some serial print ?

void notifyOnButtonPress()
  int isButtonPressed = digitalRead(D1);
  Serial.println(isButtonPressed );

Could you kindly tell me how to use a serial monitor? I don;t reeaally know

How do i add serial print to my code, could you help me with that>

I already answered

other thing :
The ESP8266 doesn’t have integrated pulldown resistors on D2, but only on D3 & D4

I’m using a nodemcu 8266 ch340 so i don;t think that’s the case for me

NodeMCU 8266 = ESP8266

Also i’m really dumb in the context of arduino and blynk programmig, could you pls tell me how D3 and D4D4 having oulldown resistors are relveant to my code?

pinMode(D3, INPUT_PULLUP);

replace by D3 or D4 and change your reed interrupt pin .

Oh do you mean replace my D1 with them? Thanks

That’s right :stuck_out_tongue_winking_eye:

Hi Man it actually didn’t work at all, when i changed to D3 it just went offline. Changing it to 1000L did not work either

1 Like

you’re welcome :stuck_out_tongue_winking_eye: