int echopin = 2;
int trigpin = 3;
int Time;
int Distance;
int buzzpin = 9;
void setup() {
// put your setup code here, to run once:
pinMode(trigpin, OUTPUT);
pinMode(echopin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigpin, LOW);
digitalWrite(trigpin, HIGH);
digitalWrite(trigpin, LOW);
Time = pulseIn(echopin, HIGH);
Distance = Time * 0.0172;
if (Distance > 30) {
digitalWrite(11, HIGH);
digitalWrite(13, LOW);
}
else {
digitalWrite(11, LOW);
digitalWrite(13, HIGH);
tone(buzzpin,1100, 300);
delay(100);
tone(buzzpin,700, 100);
delay(200);
tone(buzzpin,800, 1700);
delay(200);
}
}