long cm, duration;
const int echoPin = 7;
const int trigPin = 6;
#define LED1 14
void setup() {
pinMode(LED1, OUTPUT);
pinMode(2,OUTPUT);
pinMode(4, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(2, LOW);
delayMicroseconds(2);
digitalWrite(2, HIGH);
delayMicroseconds(5);
digitalWrite(2, LOW);
duration = pulseIn(4, HIGH);
cm = duration*0.034/2;
if (cm < 55)
{
delay(1000);
digitalWrite(LED1,HIGH);
delay(1000);
}
else
{
delay(1000);
digitalWrite(LED1,LOW);
}
}