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.
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.
In this example, we going to have TCRT5000 IR Emitter/Detector pair as an input , an LED and a DC motor as outputs. The way the code works is, if a an object is placed within the sensing range of the IR sensor, the LED turns on and the DC motor starts to rotate. This pieced of code is part of a bigger code written to control a line following robot. We shall discuss how to build and program this robot in future lessons.
Program
//Function: Interfacing TCRT5000 IR module as a digital sensor #include "TM4C123.h" // Device header #include <stdint.h> #define DETECTOR (1U<<4) #define LED_BLUE (1U<<2) #define MOTOR (1U<<6) unint_32 state=0; void Port_init(void); int main(void) { Port_init(); while(1){ if((GPIOA -> DATA & DETECTOR)==DETECTOR) { state = 0; GPIOF ->DATA &= ~LED_BLUE; GPIOA ->DATA &= ~MOTOR; } else { state =1; GPIOF -> DATA |=LED_BLUE; GPIOA -> DATA |=MOTOR ; } } } void Port_init(void) { SYSCTL->RCGCGPIO |=(1U<<0)|(1U<<5); GPIOF ->DIR |=LED_BLUE; GPIOF ->DEN |=LED_BLUE; GPIOA ->DR8R |=MOTOR; GPIOA ->DIR |=MOTOR; GPIOA -> DEN |=DETECTOR|MOTOR ; }
Add Comment