Infrared sensor

Specifications

  • Material: GaAsP/GaAlInP (gallium arsenide phosphide / gallium aluminum indium phosphide).
  • Lens type: “water”.
  • Maximum operating range specified at Ta = 25°C.
  • Voltage range: 1.1–1.5 V.
  • Operating temperature: −40°C to +85°C.
  • Peak wavelength: 940 nm.
  • Maximum current consumption: 10 μA.
  • Power dissipation: 80 mW.
  • Radiant intensity: 5–15 mW/sr.
  • Viewing angle: 30°.
  • Recommended current: 20 mA.

Overview

The infrared sensor estimates distance to surfaces that reflect light well. It is useful for detecting a black line or obstacles.

How it works: The sensor contains an infrared LED that continuously emits infrared light and a photodetector sensitive to infrared radiation. When a reflective surface is nearby, some emitted light returns to the photodetector. The closer and whiter the surface, the more light returns and the higher the sensor reading.

To check whether the infrared LED works, look at the sensor through a camera, such as a phone camera.

Using the sensor

Connecting

The sensor uses a standard 3-pin connector and plugs into any IN port on the Trackduino controller.

Programming

The sensor blocks are in the Sensors block group.

Block and generated functionDescription
Analog infrared sensor read block
int irAnalog(int port)
Returns a value from 0 to 1023 corresponding to the amount of reflected light received.
int port: port connected to the sensor.
White surface detection block
int irWhite(int port, int threshold)
Returns TRUE when the received light level is above the threshold.
int port: connected port.
int threshold: threshold from 0 to 1023.
Black surface detection block
int irBlack(int port, int threshold)
Returns TRUE when the received light level is below the threshold.
int port: connected port.
int threshold: threshold from 0 to 1023.

Example project

Following a black line

Generated code:

void setup()
{
}

void loop()
{
  if (irBlack(IN1, 500))
  {
    stopMotor(1);
    startMotor(2, 40);
  }
  else
  {
    startMotor(1, 40);
    stopMotor(2);
  }
}