OK! That tells you that my schematic is correct when it shows the LED and R as the pull up for the comparator's output. As I said earlier, the forward voltage drop of the LED (Vf) reduces the high output voltage to the measured 3.42V. That is below the 4.0V Vih(min) for the PIC input. That means that you must use an external pull up resistor to get the output high voltage to meet the PIC spec. If you don't, you can not rely on the PIC input to reliably report what the sensor is doing.0.10 volt when object is in front of sensor
And 3.42 volt when there is no object in front of the sensor
There are several lessons here that you should think about. First, always know what the specifications are for the parts you are using and make sure they are compatible. Next, always verify the voltages, signals etc. at the port pins to make sure that your circuit, sensors meet minimum specifications. Finally, understand that many things you buy for cheap from AliBaba, Amazon, eBay and the like are knock-off copies of something. They are engineered solely for the lowest cost. If you look at the schematic in the YouTube video you'll see R3, 10K is across the LED and its series resistor R1. R3 is the pull up that ensures a good high voltage. Someone thought they would save a few micro cents by deleting that resistor from the circuit. The result is that YOU have to install your own pull up resistor (like we did) or put up with possibly incorrect operation. That's why I avoid that stuff. I am not saying that you can't get some service from it but always double check the operation, voltages etc. and don't trust that what you have been sold as a KY-033 will perform like the original.
Your code should be happier with the external pull up.
Last edited: