Interfacing TCRT5000 IR Emitter/Detector Pair to Cortex-M
The TCRT500 module is a reflective sensor module. It is made up of a phototransistor coupled with an infrared LED. It’s working principle is that, the infrared LED will illuminate and bounce its light off a surface at an angle which will directly hit the phototransistor.
It is can be used to sense the distance of an object and also identify the difference between white and black based on the contrast of an object and it’s reflective properties.
Click here to jump to example source code
This module like many other sensor modules can be used both as digital sensor i.e sense just on and off and also as an analog sensor i.e. sense different ranges. Because of the limitation of sensing range of this sensor(2.5mm max.), it is mostly used as a digital sensor. However, an amplification circuit can be designed for the sensor module to boost its sensing range. In this lesson we are going to look at just the digital sensor application of this sensor. We will talk about the analog sensor application after we have provided a lesson on Analog-to-Digital Converters (ADC).
PINOUT :
Anode – +3.3 VDC
Emitter – +3.3 VDC
Emitter – Digital input pin
Cathode – GND
Collecor – GND
Programming the TCRT500 as a Digital Sensor
- Connect the 4 pins of the module as shown in the circuit diagram above.
- Set the detector pin, in our example PA4 as digital input pin.
- Poll the detector pin for HIGH state.
Specification | Rating |
Working Voltage | DC 3.3V |
Peak Operating Distance | 2.5mm |
Operating Range | 0.2mm -15mm |
Emitter Wavelenght | 950nm |
Working Frequency | 40Hz |
Trigger Signal | at least 40us |
Polling Detector Pin
We can check if detector pin is HIGH in two
- We can enable a General Purpose Timer to capture the rising edge of the detector pin. We use this method if we want the most the precise time stamp of when the detector pin goes HIGH . To learn how cpature the rising edge of a pin, please take a look at the lessons on Timers
- We can simply check the state of the detector pin bit in the detector pin data register. This is the method we shall be using in our example code since we just want to know if it is HIGH or not
We will do this by writing something like this :
while(1) { if(detector_pin == high){ perform the following actions; }
After going through the lessons on ADC’s we shall take a look at -How to sense the darkness/ whiteness of a surface using the TCRT5000 IR Sensor and also – How to sense the distance of an object using TCRT5000 IR Sensor.