#define echoPin A2
#define trigPin A1
long duration , distance ;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trigPin , OUTPUT);
pinMode (echoPin , INPUT);
}
void loop() {
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration = pulseIn(echoPin , HIGH);
distance = duration/58.2;
Serial.println(distance);
// put your main code here, to run repeatedly:
delay(50); // this speeds up the simulation
}