const int tri = 13;
const int eco = 12;
float dis;
long dur;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(tri, OUTPUT);
pinMode(eco, INPUT);
}
void loop() {
dis = getDistanceIn();
Serial.println(("Distance:" + String(dis)));
delay(10);
}
long getDistanceIn()
{
digitalWrite(tri, LOW);
delayMicroseconds(2);
digitalWrite(tri, HIGH);
delay(10);
digitalWrite(tri, LOW);
dur = pulseIn(eco, HIGH);
return((dur*0.034/2)+1);
}