#define echo 2
#define trig 3
long duration;
int distance;
void setup() {
// put your setup code here, to run once:
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo,HIGH);
distance = (duration*0.034)/2;
Serial.println("Distance: ");
Serial.println(distance);
delay(1000);
}