connection from an comparator to an optocoupler
Did you consider that the LED of the optocoupler limits the voltage at the output (pin1) to its forward voltage. I.e. the voltage divider that provides the reference voltage (at pin3) is always loaded not only by the bottom resistor (500 Ohm) but also by the branch via 300 Ohm resistor and LED.

Maybe this causes the threshold to be not where you think it is.

I recommend to connect the cathode of the LED to the ouput of the comparator (it's open drain anyway),
connect the diode's anode via a restor to Vcc and reverse positive and negative inputs of the comparator.