Question
How come it is so hard to calibrate the TCRT5000 IR reflective sensor?
Answer
Part A - Using an 1-bit ADC op-amp comparator to do the calibration
TCRT5000 is hard to calibrate unless:
(1) You read the datasheet very carefully, or
(2) You cheat by getting a module with an analog to digital op-amp.
You might find References 7 ~ 10 of my answer to the following question helpful.
What are the two sensors doing in the automatic bread production line? [closed]
Note - The above question is now closed and I am not sure if it might also be deleted later. In case you cannot read my answer, please let me know and I can move over my answer here.
Part B - Using MCP3008 10-bit ADC to calibrate the distance of the reflected object
ProtoSupplies's TCRT5000 evaluation report says the following:
initial detection can occur at up to about 6” with a fairly reflective surface with the signal rising to near 5V (full detection) at around 1”
So if you wish to also measure the distance of the reflected object, you can use the Arduino's analog input pin to get reflected signal and calculate the distance. If you are using Raspberry Pi (without any analog pins), I would recommend the common MCP3008 to do the ADC.
MCP3008 is a bit tricky for newbies to use. You can read my answer to the following question for some setting up and troubleshooting tips. If case you are new to Rpi python, I am happy to provide a fully debugged program and design notes on calibrating MCP3008.
MCP3008 ADC Troubleshooting Notes - tlfong01, EE SE, 2020aug07
/ to continue, ...
References
(1) TCRT5000 IR Reflective Sensor Module - AliExpress US$1
(2) Op-am Comparator - Electronics Tutorials
(3) TCRT5000 IR Reflective Optical Sensor Module (approx 1″ detection range) - ProtoSupplies, US$1
(4) LM324 Single Supply Quad Op-amp Datasheet - Fairchild
/ to continue, ...
Appendices
Appendix A - TCRT5000 Module Schemetic
Appendix B - Op-amp Comparator
LM324 Single Supply Quad Op-amp Datasheet - Fairchild
Appendix C ProtoSupplies's TCRT500 Evaluation Results
TCRT5000 IR Reflective Optical Sensor (approx 1″ detection range) - ProtoSupplies, US$1
To use the sensor in a minimum configuration requires two current limiting resistors, one for the IR emitter and one for the IR receiver.TCRT5000 Refective
IR Sensor Schematic
The maximum constant current through the IR emitter LED is 60mA and it has a forward voltage drop of 1.2V to 1.4V across it. In the example here, a 150 ohm resistor is used to limit current to 25mA through the emitter with an operating voltage of 5V.
The maximum current through the receiver phototransistor is 100mA. We are using a 4.7K resistor to limit the current to about 1mA since we are just looking for a logic output.
With the sensor wired up as shown here, the output will normally sit near ground due to the pull-down resistor. When a reflective surface is brought near to the sensor in order to reflect the IR light back toward the phototransistor, it will start to conduct and the voltage output will begin to rise towards 5V.
Typical circuit with an adjustable gain control
The output can be treated as an analog output and monitored with an analog input on the MCU.
In this case, the output voltage gives some indication of the distance of the object from the sensor. Depending on the reflectivity of the surface, initial detection can occur at up to about 6” with a fairly reflective surface with the signal rising to near 5V (full detection) at around 1”.
When the output is treated as a digital signal, the detection range is generally kept under 1”.
The housing has two snap in ears for mounting in a circuit board. These can be easily cut-off if desired for use in breadboards.
/ to continue, ...