IR Sensor Digital Output on Arduino

IR sensors can be used for obstacle avoidance on Arduino vehicles. Using the digital output option you can code based on a simple true false statement rather than testing against a range.

Functional Parts in the Project:

#define IR 8

int Obstacle;

void setup() {
  pinMode(IR, INPUT);
  Serial.begin(9600);
}

void loop() {
  Obstacle = digitalRead(IR);

  if (Obstacle == LOW) {
    Serial.println("STOP");
  }
 else {
   Serial.println("All Clear");

  }
  delay(500);
}

Be the first to comment

Leave a Reply