Check if power network is up, having my circuit powered via UPS
No, this will not work, if the PN connections are coming from a separate 5v phone charger / power supply. Its output is isolated from the Arduino ground, so the voltage of pin D8 will be indeterminate. The series resistors will likely protect it from damage (if you've already tried this), but you will probably be seeing a mains frequency leakage signal there.

If you connect the PN GND to the Arduino GND, then it will work as you want.