Skip to content

Instantly share code, notes, and snippets.

@e-Gizmo
Created January 11, 2014 06:49
Show Gist options
  • Save e-Gizmo/8367877 to your computer and use it in GitHub Desktop.
Save e-Gizmo/8367877 to your computer and use it in GitHub Desktop.
//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