IR LINE SENSOR

Description

  • Digital reflection sensor with on-board comparator
  • Useful for line following, anti-collision or edge detection
  • 1.5 cm range
  • Variable resistor for threshold tuning of reflective/non-reflective surfaces
  • Built in LED indicator
  • VCC input voltage 5V
  • Easy to use and set up

This IR sensor can detect the difference between a reflective and a non-reflective (white/black) surface and output a TTL signal. On a reflective/white surface the output will be low. You can use it for line following, collision risk detecting or edge detection projects. With the on-board trim pot and LED indicator it’s easy to adjust the threshold sensitivity between reflective and non-reflective surfaces to suit any environment.

The sensor has 3 pins: a ground G pin, a V+ 5 volt power supply pin and an S signal pin.

Supply voltage +3.3 to +5 VDC 20 mA
Detection distance 1.5 cm (on a white surface)
Output TTL, black or no reflection = logic HIGH, white or reflection = logic LOW
Operating temperature 0 to 50 ℃
Size 42 * 10.5 mm

Has only one signal pin. Use the male to female jumper cables to connect the module directly to the Arduino-compatible board.

To supply voltage to the board, connect the V+ pin to the 5v power pin and the G pin to the GND pin of your Arduino-compatible board. For our example, connect S to A2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
 By Dr. Mangus for Mango Labs
 IR Sensor
 V+ to 5V
  G to GND
  S to D2
 */
   
#define Digital 2   //Digital Input for IR Line Sensor Module
#define LED     13  //Build in LED at D13 pin
 
void setup() {
  //setup the input and output pins
  pinMode(LED, OUTPUT);
  pinMode(Digital, INPUT);
  digitalWrite(LED, LOW);  //ensure LED is off 
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}
 
void loop() {
    
  if(digitalRead(Digital) == 1) // if digital input is high
  {
   Serial.print("Non-Reflective");
    digitalWrite(LED,LOW);
  }
  else
  {
    Serial.print("Reflective");
    digitalWrite(LED,HIGH);
  }
  delay(300);
}
  1. In this example we are connecting:
    Arduino    IRL Sensor
    D2     —– S
    GND —– G
    5V    —– V+
  2. Download and install the Arduino environment from here or use the web editor.
  3. Download the sketch here and open or open the Arduino environment and copy the code into a blank sketch.
  4. Connect your board to your computer with the included USB cable.
  5. Select your board in Tools / Board / Arduino Uno.
  6. Select your port in Tools / Port / COM# (Arduino Uno). This may be slightly different depending on your operating system.
  7. Upload by pressing the arrow in the circle to the upper left.
  8. To open the serial monitor, press the magnifying glass icon on the upper right.
  9. Set the baud rate to 9600 on the lower right.
  10. A text will indicate whether you are on a reflective surface. The LED on pin 13 (labeled L) will turn on when you are on a reflective surface and off when you are not.That’s it!