> For the complete documentation index, see [llms.txt](https://longer-vision-robot.gitbook.io/arduino-full-stack/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://longer-vision-robot.gitbook.io/arduino-full-stack/04_infrared_sensors/029_ir_linetracking.md).

# 4.5 IR Line Tracking

## Hardware Wiring

![IR Line Tracking](https://2341898987-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LCFDbcteyTR3tQSs-5x%2F-LCFE4dCRQBMq1ajywfh%2F-LCFEUpeioZ-39dyzfTY%2F029_ir_linetracking.jpg?generation=1526059631352057\&alt=media)

## Sketch

The code can be found at [Examples\_Arduino - sensor-kit-for-arduino - \_029\_IR\_LineTracking - \_029\_IR\_LineTracking.ino](https://github.com/LongerVisionRobot/Examples_Arduino/blob/master/sensor-kit-for-arduino/_029_IR_LineTracking/_029_IR_LineTracking.ino).

```
int Led=13;       // Define LED Pin
int buttonpin=3;  // Define the line tracking sensor's pin
int val;          // Define a variable val
void setup()
{
  pinMode(Led,OUTPUT);  // Define LED as Output
  pinMode(buttonpin,INPUT); // Define line tracking sensor as input
  Serial.begin(9600);
}
void loop()
{
  val=digitalRead(buttonpin);// Assign the value of digital pin 3 to val
  Serial.println(val);
  if(val==HIGH)   // if anything detected by line tracking sensor, LED starts flashing.
  {
    digitalWrite(Led,HIGH);
  }
  else
  {
    digitalWrite(Led,LOW);
  }
}
```
