ESP8266 first code help

Juraj:
again, why analogRead? it doesn't work on io pins of esp8266. use digitalRead

The esp8266 does have 1 analog to digital channel so analogRead(0) works.
However, I do agree that if the sensor provides a digital output, that analogRead() is not necessary.

I think one big issue here is that we don't know which specific esp8266 module is being used.
There are many and they vary substantially on what pins are available and some of the external h/w wrapped around the pins on the module.

We are also not seeing actual full code of what is being used just small snippets.
This creates many unknowns and ends up creating some confusion since the answers being provided have to take into consideration issues on boards that the OP may not be using.

--- bill