Home » Electronica » Arduino » TCRT5000 Module (linetracker)

TCRT5000 Module (linetracker)

Learn how to use the light module (linetracker). DYOR robot uses this module to track lines on the ground using the contrast (between black and white). Working principle, connection diagrams and programming examples with Facilino and Arduino.

How does it work?

TCRT5000 module emits an infrared light using a fotodiode that it’s reflected towards the surface. The light is reflected so that a fototransistor receives the amount of light reflected, which is in the end transformed into a voltage. The next image, when the fotodiode, when the fototransistor receives an amount of light will let the current flow so that the voltage will tend to 0V, while if no source light is receive, the fototransistor will be in ‘open circuit’, meaning that we will be measuring basically Vcc voltage.

The amount of light received might depend on many aspects, mainly with the distance to the surface and the color of the surface. It has a filter to filter out ambient light, but it’s use outdoors is not recommended, because the sensor becomes “blind” as an effect of infrared components of the sun light. This kind of sensors can also be used as obstacles detectors (with a very short-range about 15mm) and eventually they are used as contact-less switches. In robotics, their main application is to use them as line tracking module to distinguish the color of the ground (gray-scale). In particular, if the ground is dark or black, the reflection is very poor and the signal we measure is close to Vcc, while if the ground is white, then the amount of light reflected is high and the signal received will close to 0V.

The module has an analog comparator, meaning that with a potentiometer we can adjust a reference value we consider that the amount of light HIGH or LOW on its digital output. Therefore, this is useful when used as a digital switch.

Sensor Properties

  • Measuring range 0.5mm and 15mm.
  • Wave length 950nm.

Connection

The TCRT5000 uses four connections (although we won’t, usually, use the digital output):

  • VCC: Power. Connect to +5V pins.
  • GND: Ground. Connect to 0V (GND) pins.
  • DO: Digital output. It can be connected to any digital pin of Arduino
  • AO: Analog output. It must be connected to analog pins of Arduino.

Here we show a connection diagram using Arduino Nano v3.0. Signal A0 has been connected to analog pin A0, signal DO has been connected to pin A4 (as digital input). This is because, despite of the pin names, most of analog input pins can be used digital inputs/output too. Pins VCC and GND can be connected to any +5V and 0V pins of Arduino Nano v3.0, respectively:

Here, you can download the Fritzing diagram:

Programming

In this example, we show on the console the measured value, it should be between 0-1023 and change depending of the colour of the reflected surface:

Here, you can download Facilino’s code:

We can use Facilino’s console or Arduino IDE console to display the numbers. In the following image, we get values over 800 for black objects and under 50 for white objects.

Now, we will use the analog signal but it will be divided into three cases: white, gray and black. So when the amount of light is below the 40% of the reference light, we will consider the ‘white’ case. If the amount of light is between 40% and 60%, then the ‘gray’ case will be executed. Otherwise, the ‘black’ case will be executed. To adapt this to any situation, we need to calibrate the sensor first, by assigning the amount of level for ‘white’ and ‘black’ cases. This calibration procedure will be done during the setup. So, we need to annotate the values of ‘white’ and ‘black’ beforehand, using the code of the previous example.

In next example, we will use continuous rotation servos (SCR) connected to pins 9 and 5, respectively, to implement a line following routing using these three cases.

Here, you can download Facilino’s code:

Now, we show a different example to implement the line following application using Facilino’s code. The main difference with respect to the previous example is that the signal received will not be divided into three cases. We will directly use this signal and convert it into a rotation speed for the robot. There’s one only adjustable parameter which is the gain that we want to turn. The higher the gain the faster will converge to the line, but it can make the robot oscillating (rotating from one side to the other). The smaller the gain, the robot will turn slower, but at least won’t be oscillating, so it’s up to you. The distance of the infrared sensor to the wheels can significantly affect to. So if the distance is short, the robot is prone to oscillate. Again, we will need calibration values as before.

Here, you can download Facilino’s code:

 

 

 


Leave a comment