# 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.
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.