#define Trig 12
#define Echo 14
#define Led 6
long width, distance;
void setup()
{
Serial.begin (9600);
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
pinMode(LED, OUTPUT);
}
void loop()
{
digitalWrite(Trig, 0);
delayMicroseconds(2);
digitalWrite(Trig, 1);
delayMicroseconds(10);
digitalWrite(Trig, 0);
width = pulseIn(Echo, 1);
distance = width/58.2;
Serial.print(" Distance is: ");
Serial.print(distance);
Serial.println(" cm");
if (distance<100)
digitalWrite(Led,1);
else
{
digitalWrite(Led,0);
delay(1000);
}
}