Skip to content

Instantly share code, notes, and snippets.

@riebschlager
Created January 9, 2017 15:14
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 riebschlager/d7f1c2446716175fa7a793bc58b8f985 to your computer and use it in GitHub Desktop.
Save riebschlager/d7f1c2446716175fa7a793bc58b8f985 to your computer and use it in GitHub Desktop.
// Double-check that these pins are correct.
const int sensorPin = 9;
const int relayPin = 10;
const int threshold = 50;
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);
}
void loop() {
long distance = pulseIn(sensorPin, HIGH) / 147;
if (distance < threshold && distance != 0) {
Serial.println(distance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment