Created
December 22, 2018 09:09
-
-
Save detik19/920b5780dd779fef895b41af5c95a0ba 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
#define trigPin 11 | |
#define echoPin 12 | |
#define led 11 | |
#define led2 10 | |
void setup() { | |
Serial.begin (9600); | |
pinMode(trigPin, OUTPUT); | |
pinMode(echoPin, INPUT); | |
} | |
void loop() { | |
long duration, distance; | |
digitalWrite(trigPin, LOW); | |
delayMicroseconds(2); a | |
digitalWrite(trigPin, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trigPin, LOW); | |
duration = pulseIn(echoPin, HIGH); | |
distance = (duration/2) / 29.1; | |
Serial.print(distance); | |
Serial.println(" cm"); | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment