TK57DIGITALANALOGbeginner

Reflective Optical Sensor

Light out, light back. Line following, edge detection, and counting things going past on a belt — as long as the surface plays fair.

Comes in this kit — not sold separately

Specifications

TypeReflective optical sensor (IR emitter and phototransistor)
RangeA few millimetres to about 2 cm
OutputDigital threshold, and analog on some variants
Supply voltage3.3 V or 5 V

What it is

An infrared LED and a phototransistor pointing the same way. Something reflective in front sends light back; something dark or distant does not.

It measures reflectance, not distance, and conflating the two is the usual mistake. A white surface 2 cm away and a grey one at 1 cm can read identically. For line following that is fine — you only need to tell the line from the background — and for measuring a gap it is useless.

Range is short by design, a couple of centimetres at most, because reflected light falls off fast. Mount it close and shield it: ambient light, especially sunlight, adds a signal that has nothing to do with your surface.

Calibrate against the actual materials. Read the line, read the background, and put the threshold between them.

Reflective Optical Sensor — front
Front
Reflective Optical Sensor — back
Back
Reflective Optical Sensor — side
Side

Pinout

  • GND (negative): Like the negative terminal (-) of a battery, connect to the control board's GND
  • VCC (positive): Like the positive terminal (+) of a battery, connect to the control board's 3.3V or 5V (this module supports both 3.3V and 5V)
  • NC (no connection): No actual circuit connection, included for unified interface, can be left unconnected
  • SIGNAL (signal output): Line tracking detection output pin, connect to the control board's digital pin (e.g. Arduino D2 or Pico GPIO 0)
    • Outputs HIGH (HIGH/1) when black line is detected
    • Outputs LOW (LOW/0) when white line is detected (or no black line detected)

Wiring

Reflective Optical Sensor wiring

  1. GND → Control board GND
  2. VCC → Control board 3.3V or 5V
  3. SIGNAL → Control board digital pin (use the pin defined in your program)

Example

// Pin number: change this to match your wiring
#define TRACKER_PIN 2  // Arduino digital pin connected to SIGNAL (e.g. D2)
#define LED_PIN 13     // LED pin (Arduino built-in LED on pin 13, or external LED)

void setup() {
  // Initialize pin modes
  pinMode(TRACKER_PIN, INPUT);  // Set line tracker pin as input (to read detection state)
  pinMode(LED_PIN, OUTPUT);     // Set LED pin as output (to control LED on/off)
  
  // Start serial for debugging (9600 baud)
  Serial.begin(9600);
  
  Serial.println("Line tracker program started");
  Serial.println("LED on when black line detected, LED off when white line detected");
}

void loop() {
  // Read line tracker state
  int trackerState = digitalRead(TRACKER_PIN);  // Read sensor pin level: HIGH(1)=black line detected, LOW(0)=white line detected
  
  // Control LED based on detection state
  if (trackerState == HIGH) {
    // Black line detected: LED on
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Black line detected - LED on");
  } else {
    // White line detected: LED off
    digitalWrite(LED_PIN, LOW);
    Serial.println("White line detected - LED off");
  }
  
  delay(100);  // Brief delay to avoid reading too fast
}
Reflective Optical Sensor running on an Arduino Uno

When it doesn’t work

It reads the same over the line and off it.
Not enough contrast in infrared. Some inks that look black to you reflect IR. Test with the real surface and try matte black tape.
It works indoors, not near a window.
Sunlight is full of IR. Shield the sensor, get it closer to the surface, or switch to a modulated sensor.
Can I measure distance with it?
Not reliably — reflectance and distance are confounded. Use TK50 for distance.

Edit this page — content/modules/reflective-optical-sensor.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Reflective Optical Sensor

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum