Detect if multiple LEDs on external circuit are turned on with ESP8266

Hey guys,

I’ve gotten a bit stuck with my latest project as I’ve been trying to automate and control some 24V air conditioner dampers. These dampers are controlled at a central touch panel which has some momentary buttons and some LEDs to indicate the damper status (open/closed). I’m using some relays to simulate button presses, but ideally I want to maintain the functionality of the existing control panel, so I want to use a NodeMCU ESP8266 to detect if LED lights are turned on and off for each dampers.

Images of front/rear of control panel.

I initially tried connecting the LED terminal positive to D1/2/3 and LED terminal negative to G on the NodeMCU respectively (as I measured low voltage of ~1.97V when the LED light is on), however I noticed some weird behaviour with the LED lights flashing and not being detected via HomeAssistant. If I hook just one LED then it works perfectly and gets detected and the LED turn on/off correctly when either pressing the button manually or toggling via the relay.

circuit.drawio (1)

I thought maybe it might be due to a common ground issue, or some interference I’m introducing. The interwebs suggested I try an optocoupler/optoisolator, as per the below diagram.

Now I am able to detect the open/closed state, but the LEDs no longer turn on or off :frowning: .

Im sure I am doing something silly here, but my electronics knowledge is limited so I can’t seem to figure it out. The moment I sever the line between the Optocoupler Collector port and D1/2/3 then the LED light turns on again.

My ESPHome Yaml code below. Nothing very special other than the INPUT_PULLUP

binary_sensor:
  - platform: gpio
    pin:
      number: D1
      mode: INPUT_PULLUP
      inverted: false
    name: "Damper 1 State"
    device_class: opening
    filters:
      - delayed_on: 10ms
  
  - platform: gpio
    pin:
      number: D2
      mode: INPUT_PULLUP
      inverted: false
    name: "Damper 2 State"
    device_class: opening
    filters:
      - delayed_on: 10ms
      
  - platform: gpio
    pin:
      number: D3
      mode: INPUT_PULLUP
      inverted: false
    name: "Damper 3 State"
    device_class: opening
    filters:
      - delayed_on: 10ms

Any ideas?

You’re almost there. The problem you’re having is that the forward voltage of the optocoupler is lower than the turn on voltage of the LED. So as they are in parallel the optocoupler clamps the voltage too low for the led to turn on. There is a simple solution. Put a low value resistor in series with the optocouler to drop some extra voltage.

Looking at the datasheet for the 4N35 it has a forward voltage of 1.3V. So as it needs about 5 to 10mA to turn on the resistor should be:

(1.97V-1.3V) / 5mA = 134 Ohms

to

(1.97 -1.3) / 10mA = 67 Ohms.

Use a 100 Ohm resistor.

Put them here:

Or in the negative leads. Whichever is easier.

1 Like

At ofcourse. How silly of me. Thanks so much Tom. I’ll give it a tomorrow :smile:

Unfortunately it didn’t work for me as the LED still doesn’t turn on while connected to the optocoupler with the resistor in series, but I think what you have proposed is sound. I measure a forward voltage of ~1.126V (without the resistor), but I can’t seem to find any specific datasheet for my 4N35s, so I don’t know what current value I’m working with. Some datasheets indicate 20-50mA.

There was a comparable solution mentioned over at StackExchange, where they recommended using a resistor of 390-470Ω based on 1mA for a 4N25 optocoupler, but they also suggest using an SFH618A which is low current and high CTR. So now I’m a bit unsure. I don’t want to go frying the circuit by placing too low or too high a resistor :frowning:

You won’t fry it by placing too high a resistor.

Captureing this thread because it comes closest to my case.
I have a similar situation with a board of multiple LED´s.
But somehow i can not get it to work. The detection per short cutting is working and the state is shown, so I can checkmark the software function. But with the use of the optocoupler nothing happen.

I have green and red LED’s on the board (right and left handed on the picture). To my suprise the green LED has a voltage of 1 Volt. Suggesting that the digit on the take some Volts as well.
As I am not a specialist, I believe that the 1V is to less for the optocoupler. Can someone confirm or give me a hint how to solve it. I use as well the 4N35 and have a 4N28 as well available.

Unfortunatly I can not upload the front view due to board restrictions for new users.
The board has in the middle an IC and top middle is a two segment digit.
The lowest circuit path (which goes down and than divide into left and right) is +5V.