Hi,
about your circuits of post#3:
* The first is an OPAMP LM324 but used as comparator.
--> I recommend to use a comparator when you need a comparotor circuit.
--> The 10k with the diode connection makes the circuit slow. Uusally there is light on the soensor, so there is current through the sensor, pulling the voltage against GND. But the "release", when an object crossing the sensor is slow. I thas no protection against ambient light. Is the sensor protected against ambient light?
* the second circuit is a three stage amplifier folowed by a comparator circuit with hysteresis. But the input circuit is very slow.
***
I recommend to read some application notes about photodiode connection to a transimpedance amplifier.
Usually any capacitance makes a circuit slow. The benefit of the transimpedance amplifier is, that the voltage across the diode never changes (negligible). With no voltage change the charge current of the capacitance is neglegible. The circuit is fast.
--> Use a high speed amplifier. Use a low noise reference voltage for biasing the diode (to In+ of the transimpedance amp). Best is to add an RC low pass filter.
Select the feedback resistor in a way that the opamp output never saturates.
To get a reliable threshold with a bit of ambient light suppression: I ´d add an RC lowpass combined with a voltage divider (to VRef, about 90%) at the transimpedance amp output. This gives the one input to a comparator. The other imput is the direct connection of the transimpedance output.
How it works:
Lets say you use single +5 as supply. 1.25V as bias reference. Use RR IO opamp and comparator.
IN+ is 1.25V. The same is across the photodiode. choose feedback so that with full light to the photodiode there is max. 4.5V at OPAMP output.
The LPF at the output should be slow ( tau of about 1s or so), The LPF will give an output voltage of (1.25V + (4.5V -1.25V) * 0.9 after a while. = 4.175V
Every time an object passes the sensor the photodiode current decreases very fast and the OPAMP output voltage decreases also. Maybe from 4.5 down to 4.0V.
The LPF voltage is slow, so you may calculate with 4.175V or a bit less.
But the direct output changes fast from 4.5 to 4.0V... Therefore the comparator switches state.
The LPF gives a bit of ambient light suppression. But if there is a very slow object passing the sensor the LPF may be problematic.
Hope this helps.
Klaus