Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save giljr/65689977f1e5f9ed3e31b3aaacb9ac26 to your computer and use it in GitHub Desktop.
Save giljr/65689977f1e5f9ed3e31b3aaacb9ac26 to your computer and use it in GitHub Desktop.
Garages are getting tighter and tighter: page: https://goo.gl/pj20lS
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
char data = 0; // Variable for storing
#define trigPin 13
#define echoPin 12
#define stop_LED 11
#define go_LED 10
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
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
Serial.println("STOP");
mySerial.println("STOP"); // S - TOP
mySerial.println(distance);
digitalWrite(go_LED, LOW);
}
else {
digitalWrite(stop_LED, LOW);
//mySerial.print('G'); // G - O
digitalWrite(go_LED, HIGH);
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment