Created
January 9, 2017 15:14
-
-
Save riebschlager/d7f1c2446716175fa7a793bc58b8f985 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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