HolyC0w

lab3_IR

Apr 11th, 2023
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int LEDpin = 12;
  2. int obstaclePin = 7;
  3. int hasObstacle = LOW;  // LOW MEANS N O OBSTACLE
  4.  
  5. void setup() {
  6.   pinMode(LEDpin, OUTPUT);
  7.   pinMode(obstaclePin, INPUT);
  8.   Serial.begin(9600);
  9. }
  10. void loop() {
  11.   hasObstacle = digitalRead(obstaclePin);
  12.   if (hasObstacle == HIGH) {
  13.     Serial.println("Stop something is ahead!!");
  14.     digitalWrite(LEDpin, HIGH);
  15.   } else {
  16.     Serial.println("Path is clear");
  17.     digitalWrite(LEDpin, LOW);
  18.   }
  19.   delay(200);
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment