const int trigPin = 11;
const int echoPin = 12;
const int ledPin = 2;
long duration;
int distance;
void setup ()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop ()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH );
delayMicroseconds(10);
duration = pulseIn(echoPin, HIGH);
distance =duration*0.034/2;
if (distance < 59)
digitalWrite(ledPin, LOW);
else digitalWrite(ledPin, HIGH);
delay (500);
Serial.println(distance);
}