Lesson 24 Tracking Sensor

Share for us


A tracking sensor (as shown below) has the same principle with an obstacle avoidance sensor but has small transmitting power.


– 1 * SunFounder Uno board

– 1 * USB data cable

– 1 * Tracking sensor module

– Several jumper wires

Experimental Principle

When the infrared transmitter emits rays to a piece of paper, if the rays shine on a white surface, they will be reflected and received by the receiver, and pin S will output low level; If the rays encounter black lines, they will be absorbed, thus the receiver gets nothing, and pin S will output high level.

In this experiment, we will use an obstacle avoidance sensor module and an LED attached to pin 13 of the SunFounder Uno board to build a simple circuit to make a tracking light.

Since an LED has been attached to pin 13, connect the pin out to D8 of the SunFounder Uno board. When the tracking sensor detects reflection signals (white), the LED will be on. Otherwise, it will be off (black line).

Experimental Procedures

Step 1: Build the circuit

                               Tracking Sensor Module               SunFounder Uno

                                             S ——————————————– D8

                                             –  ——————————————- GND

                                             + ——————————————- 5V

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorial on our website)

Step 3: Compile

Step 4: Upload the sketch to SunFounder Uno

Now, draw two black thick lines on the paper. If the rays emitted by the sensor encounter the black lines, the LED attached to pin 13 on SunFounder Uno board will light up. Otherwise, it will go out.


const int tracingPin = 8;
const int ledPin = 13;void setup()
pinMode(tracingPin, INPUT);
pinMode(ledPin, OUTPUT);
}void loop()
int val = digitalRead(tracingPin);
if(val == HIGH)
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);