int trigPin = 11;
int echoPin = 12;
int LEDPin = 13;
long duration, cm, inches;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
cm = (duration/2) / 29.1;
inches = (duration/2) / 74;
if (cm < 100)
{
digitalWrite(LEDPin, LOW);
}
else {
digitalWrite(LEDPin, HIGH);
}
}