//Obstacle detection using IR sensor:
const int IRsensor=12;
const int Led= 4;
int sensordata;
void setup() {
// put your setup code here, to run once:
pinMode(IRsensor, INPUT);
pinMode(Led, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
sensordata=digitalRead(IRsensor);
if (sensordata==1) {
Serial.println("Obstacle not detected");
digitalWrite(Led, HIGH);
}
else {
Serial.println("Obstacle detected");
digitalWrite(Led, LOW);
delay(1500);
}
}