Skip to content

Instantly share code, notes, and snippets.

@giljr
Created May 14, 2017 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giljr/6d346bc2c2c97f0d6812ec8475e484e7 to your computer and use it in GitHub Desktop.
Save giljr/6d346bc2c2c97f0d6812ec8475e484e7 to your computer and use it in GitHub Desktop.
The garages are getting more and more tight: page: https://goo.gl/pj20lS
#define trigPin 13
#define echoPin 12
#define stop_LED 11
#define go_LED 10
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(stop_LED, OUTPUT);
pinMode(go_LED, OUTPUT);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration ) / 58.2;
if (distance < 5) { // This is where the LED On/Off happens
digitalWrite(stop_LED, HIGH); // When the Red condition is met, the Green LED should turn off
digitalWrite(go_LED, LOW);
}
else {
digitalWrite(stop_LED, LOW);
digitalWrite(go_LED, HIGH);
}
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment