Created
January 11, 2014 06:49
-
-
Save e-Gizmo/8367877 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
//Demo sketch | |
//This sketch will output distance into via the UART port | |
//port assignment | |
//change as may be necessary | |
const int trigger = 6; | |
const int echo = 7; | |
float distance; | |
void setup(){ | |
Serial.begin(9600); | |
pinMode(trigger, OUTPUT); | |
pinMode(echo, INPUT); | |
} | |
void loop(){ | |
//Trigger US-100 to start measurement | |
//Set up trigger | |
digitalWrite(trigger, LOW); | |
delayMicroseconds(5); | |
//Start Measurment | |
digitalWrite(trigger, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trigger, LOW); | |
//Acquire and convert to mtrs | |
distance = pulseIn(echo, HIGH); | |
distance = distance*0.0001657; | |
//send result to UART | |
Serial.println(distance); | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment