int echopin = 2;
int trigpin = 3;
int Time;
int Distance;
int buzzpin = 9;
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
pinMode(buzzpin, OUTPUT);
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(13, HIGH);
digitalWrite(11, LOW);
} else {
digitalWrite(13, LOW);
digitalWrite(11, HIGH);
tone(buzzpin, 1100, 300);
delay(100);
tone(buzzpin, 700, 100);
delay(200);
tone(buzzpin, 800, 1700);
delay(200);
}
}