Code 2 Buzeer Gun Control
Code 2 Buzeer Gun Control
// we create an instance of the "SR04" object type (this is from the library file
we include)
// the argument for creating the instance is the trigger pin and echo pin we
specified.
SR04 sr04 = SR04(ECHO_PIN, TRIG_PIN);
void setup() {
delay(1000);
}
void loop() {
//
a = sr04.Distance();
Serial.print(a);
Serial.println("cm");
// LED and buzzer go on when measured distance < our threshold value
WarningDistance
if (a <= WarningDistance) {
digitalWrite(ledpin, HIGH);
digitalWrite(buzzerpin, HIGH);
}
// if distance>threshold, we turn off LED and Buzzer
else {
digitalWrite(ledpin, LOW);
digitalWrite(buzzerpin, LOW);
}
delay(300);
}