I’ve edited your code so that it displays correctly.
When you post code on the forum it must have triple backticks at the beginning and end. This information is explained in the information displayed when you create a new thread.
Triple backticks look like this:
```
Please format your code correctly in future, or it will probably be deleted.
You’re using two different ways of referencing the I/O pins on your NodeMCU. You start off using GPIO numbers for pins 2 and 16, then switch to the ‘D’ numbers that are screen printed on the NodeMCU board. You use pins D1, D2 and D3, which are GPIO pins 5, 4 and 0 respectively.
Mixing the way you reference pins in this way can be confusing, as you could think that you were using two separate pins for two separate tasks, but in reality you’re using the same pin with two different names.
So, in total you’re using GPIO pins 0, 2, 4, 5 and 16.
If you read this topic:
You’ll see that pins 0 and 2 aren’t recommended for use.
I think that what’s happening is that you’re pilling one of these pins to the wrong state at boot-up, so either putting the NodeMCU into flash mode, or disabling the onboard Wi-Fi.
Pete.