int trig = 10;
int echo = 11;
void setup() {
// put your setup code here, to run once:
pinMode(11, INPUT);
pinMode(10, OUTPUT);
Serial.begin(9600);
}
void loop() {
delay(500);
// put your main code here, to run repeatedly:
long duration, distance;
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = (duration / 2) / 29.1;
Serial.println(distance);
}