Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Last active March 16, 2017 13:19
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 maxpromer/5d395db3d9dc62012c5c08a86178b858 to your computer and use it in GitHub Desktop.
Save maxpromer/5d395db3d9dc62012c5c08a86178b858 to your computer and use it in GitHub Desktop.
/*
* Codeing By IOXhop : www.ioxhop.com
*/
#define US100_Trig_PIN 12
#define US100_Echo_PIN 13
void setup() {
pinMode(US100_Trig_PIN, OUTPUT);
pinMode(US100_Echo_PIN, INPUT);
Serial.begin(9600);
}
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