# 4.4 IR Obstacle Avoidance

## Hardware Wiring

![Obstacle Avoidance](/files/-LCFEAcRAROWO78Dd4z-)

## Sketch

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

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://longer-vision-robot.gitbook.io/arduino-full-stack/04_infrared_sensors/028_ir_obstacleavoidance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
