I'm taking a 3.3v output from the NVR video surveilance alarm led. Since this NVR doesen't have alarm output I've removed the alarm LED and used this as input for my ESP8266. Everyting works fine but I can't understand why is the output now inverted i.e. when the alarm is triggered the output is LOW and when it is not triggered it is HIGH. This happenes when I connect GND from NVR to GND on the ESP8266. If GNDs are not connected, trigger works as supposed - HIGH on alarm and LOW on no alarm.
A direct connection from NVR alarm LED driver to ESP8266 digital I/O input is possible only if the GND of one connects to GND of other. It is assumed that both NVR and ESP8266 are powered with a DC supply of similar voltage (+3.3V?):
- Vdd1 can differ from Vdd2
- GND of NVR is isolated from GND of ESP8266 - no electrical connection exists between NVR and ESP8266.
- you have the option of sensing logic high or sensing logic low
The disadvantage of opto-coupler is loss of the NVR LED alarm indicator, since the opto-coupler internal LED (which is not visible) replaces it. R1 (assumed 100 ohms) and R4 (also assumed 100 ohms) are the NVR LED's present series resistor. The opto-coupler internal infra-red LED simple replaces the visible LED:
At left, R2 is a pull-down resistor at ESP8266 digital input. When the opto-coupler LED is inactive, R2 pulls to logic low and only goes high when LED current flows.
At right, R3 is a pull-up resistor for ESP8266 digital input. When the opto-coupler LED is inactive, R3 pulls to logic high and only goes low when LED current flows.