The problem is that when I connect R1 to R3 and the photodiode + pin, the voltage that usually is 4.56 and above drops immediately to a few 300mV in that node.
BTW not all opamps can be used as comparators, rail-to-rail or otherwise, and in general you should use a comparator as a comparator, not an opamp, because they are way way better at the job.
No, I mean have you checked the input and output voltages for the opamp in the datasheet? You are expecting them to work at 4.1V from 5V supply, but they can't.
At 1M that R3 has no effect at all on the circuit as R1 will completely dominate.
I made up this circuit.
I was trying to get a voltage comparator with Hysteresis so that when a fast object passed in front of the photodiode the comparator would detect the small voltage drop and give a signal to an Arduino board.
In the datasheet, is the topic 7.7 "INPUT VOLTAGE RANGE" the reason it won't operate from 4.1 to 5V? In other words, it's range is only 0 to 3.5V if Vs=5V?
Alas you chose the wrong configuration which heavily loaded the voltage you were trying to sense.
You want to observe the voltage at the junction of the photodiode and 1M resistor? The you need an impedance much higher than 1M (not 200 ohms!).
You need a true rail-to-rail device for this, be it a comparator or an opamp, if you want to work right up against the +ve rail.
Make life easy and work down near ground - far more devices go to the -ve rail than to the +ve rail. In particular the LM358 should work close to its negative rail.
So redo the divider: photodiode to ground, 1M to 5V.
The way to wire this is inverting input sensing the photodiode, non-inverting input to the voltage reference (which would be 0.9V with things the other way up), adding hysteresis in that part of the circuit where it doesn't load the diode divider.
I think I understand now. I had no idea that there was such a thing as the Input and Output voltage range.
I'll follow your advice, thank you very much for your time and attention!