# Trigger input with varying input voltages

Currently I am trying to build a circuit, with the goal of triggering a pin of an ESP8266 from varying input voltages (in the range of 5 to max 15 volts it should get triggered). Also the input should be seperated from the ESP.

What I was thinking to do was:

• Use an optocoupler for the input voltage (currently thinking about the pc817)
• Calculate the resistor so that min voltage and max voltage would work (current range of the pc817 is 20mA - 50mA, and Voltage Range is 1.2 (standard) to 1.4):
• 15V: (15V - 1,2V) / 0,05A = 276 ohm (already calculated for absolute max current)
• 5V: (5V-1,2V) / 0,02A = 190 ohm

So which resistor should I use to allow 5-15V in this optocoupler? Or is there any better circuit option/better optocoupler that allows something like this to be achieved?

That looks dodgy. You haven't linked to a datasheet but the fact that you mention 1.2 to 1.4 V looks like you are referring to the $V_f$ of the opto-coupler LED. If you vary the input voltage by a factor of three your opto-coupler LED current will vary by close to the same amount.

Your ESP trigger will depend on the output of the opto-isolator and the pull-up resistor. You want this to switch very cleanly so you should be switching the LED on hard rather than just on the edge of working at 5 V.

You could consider a constant current driver for the opto-LED.

Figure 1. This switched constant-current driver provides a constant-current to the LED over a range of supply voltages and independent of the LED’s forward voltage. Source: Simple constant-current driver.

In your case you can connect IN and Vbb together. L1 represents the LED in the opto-coupler. For 10 mA R2 should be about $R = \frac {V}{I} = \frac {0.6}{0.01} = 60 \ \Omega$. Pick the nearest standard value. See my linked article for more.

• Thank you for your input. Would a component like the NSI45020T1G be enough in front of my optocoupler (datasheet.octopart.com/…). Also: would I still need a resistor or is this already included in such CCRs? – Eggi Aug 31 '18 at 3:36
• If your opto-isolator can handle 20 mA continuously then that would be a fine choice. I was going to suggest something similar but wasn't sure about availability. – Transistor Aug 31 '18 at 6:16