Created
May 22, 2017 17:46
-
-
Save maxpromer/568c1a306b3e385b597265dbaa8b1884 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 US100_Trig_PIN 22 | |
#define US100_Echo_PIN 23 | |
void setup() { | |
pinMode(US100_Trig_PIN, OUTPUT); | |
pinMode(US100_Echo_PIN, INPUT); | |
Serial.begin(115200); | |
} | |
void loop() { | |
digitalWrite(US100_Trig_PIN, LOW); | |
delayMicroseconds(5); | |
digitalWrite(US100_Trig_PIN, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(US100_Trig_PIN, LOW); | |
unsigned int PulseWidth = pulseIn(US100_Echo_PIN, HIGH); | |
unsigned int distance = PulseWidth * 0.1657; | |
Serial.print("Distance is "); | |
Serial.print(distance); | |
Serial.println(" mm."); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment