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:
- Arduino Uno – https://store.arduino.cc/usa/arduino-uno-rev3
- IR Sensor – https://amzn.to/2IDw7SE
#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