Home Code TCRT5000 Reflective Optical Sensor module example

TCRT5000 Reflective Optical Sensor module example

by shedboy71
[lebox id="1"]

In this example we look at a module based on the TCRT5000 Reflective Optical Sensor with Transistor Output. A very basic description of the TCRT500 is that it is an Infrared LED and an Infrared detector. It works by transmitting a beam of Infrared light downward towards a surface which is then reflected back and read by the detector

When the infrared transmitter emits a beam of light to a piece of paper, if the rays shine on a white surface, they will be reflected and in turn be received by the Infrared detector , and pin S on the module will output a low level; If the beam of light encounters a black line, they will be absorbed, thus the Infrared detector gets nothing, and pin S will output a high level.

So this module basically acts like a simple switch when it gets close to a white / black object. You can adjust the sensitivity with the potentiometer on the module

You have to be about 2.5cm from white paper but some objects you may have to be slightly closer for other objects. This is the module that I used – there are a couple of minor variations to this one but generally they all work the same way.

In this example, we will use an IR track sensor module and the on-board LED of an Arduino Uno to build a simple circuit to make a tracking line. You need to connect the pin S to digital pin 2 of the Uno board.

Connection

Code

Very easy to use

[codesyntax lang=”cpp”]

const int tcrtPin = 2; //the tracking module attach to pin 2
const int ledPin = 13;

void setup()
{
  pinMode(tcrtPin, INPUT); // set trackingPin as INPUT
  pinMode(ledPin, OUTPUT); //set ledPin as OUTPUT
}

void loop()
{
  boolean val = digitalRead(tcrtPin); // read the value of tcrt5000
  if(val == HIGH) //if it is HiGH
  { 
    digitalWrite(ledPin, LOW);
  }
  else
  {
    digitalWrite(ledPin, HIGH);
  }
}

[/codesyntax]

 

Output

Cover and uncover the tcrt5000 sensor – the onboard LED of your Arduino should go on and off

 

Link

1 PCS Tracking Sensor IR TCRT5000 Infrared Obstacle Avoidance sensor for Arduino AVR PIC

Share
[lebox id="2"]

You may also like

Leave a Comment