Skip to content

Instantly share code, notes, and snippets.

@AungWinnHtut
Created August 15, 2018 15:02
Show Gist options
  • Save AungWinnHtut/e47263f94d275180272efa6133337882 to your computer and use it in GitHub Desktop.
Save AungWinnHtut/e47263f94d275180272efa6133337882 to your computer and use it in GitHub Desktop.
int LED = 13; // Use the onboard Uno LED
int obstaclePin = 7; // This is our input pin
int hasObstacle = HIGH; // HIGH MEANS NO OBSTACLE
void setup() {
pinMode(LED, OUTPUT);
pinMode(obstaclePin, INPUT);
Serial.begin(9600);
}
void loop() {
hasObstacle = digitalRead(obstaclePin); //Reads the output of the obstacle sensor from the 7th PIN of the Digital section of the arduino
if (hasObstacle == LOW) //LOW means something is ahead, so illuminates the 13th Port connected LED
{
Serial.println("Stop something is ahead!!");
digitalWrite(LED, HIGH);//Illuminates the 13th Port LED
}
else
{
Serial.println("Path is clear");
digitalWrite(LED, LOW);
}
delay(200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment