Created
August 18, 2016 12:55
-
-
Save maeishoj/cdd1e931105c21461ab68d228ca59bb2 to your computer and use it in GitHub Desktop.
Red Ultrasonic 5 PIN
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 TRIG A2 | |
#define ECHO A3 | |
void setup() { | |
Serial.begin (9600); | |
pinMode(TRIG, OUTPUT); | |
pinMode(ECHO, INPUT); | |
} | |
void loop() { | |
int duration, cm; | |
digitalWrite(TRIG, LOW); | |
delayMicroseconds(2); | |
digitalWrite(TRIG, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(TRIG, LOW); | |
duration = pulseIn(ECHO, HIGH); | |
cm = duration / 58; | |
Serial.print(cm); | |
Serial.println(" cm"); | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment