sr501 and buzzer time delay

HI

I've just connected my sr501 pir sensor to my arduino with a buzzer turning on when the motion detector is high.
the sr501 minimal time delay is 3-5 sec but its really long when you listen to this buzzer.
I tried to change it with code but I probably miss something because its not working.
I tried to chgnde to buzzed to low but I guess itn stop the electricity but dont stop it.
is there a way to change it?
this is the code(not mine):

//define the pins
int LED = 4;
int PIR = 7;
int Buzzer = 2;

void setup() {
  //define the LED and Buzzer pin as output
  pinMode(LED, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  //define the sensor pin as input
  pinMode(PIR, INPUT);
}

void loop() {
  //using the digitalRead function we will read the signal of the sensor
  int value = digitalRead(PIR);
  //if its high or if an any object is detected it will activate the LED and Buzzer
  if (value == HIGH){
    digitalWrite(LED, HIGH);
    digitalWrite(Buzzer, HIGH);
    delay (300);
    digitalWrite(Buzzer, LOW);  
  }
  else {
    digitalWrite(LED, LOW);
    digitalWrite(Buzzer, LOW);
  }
}

TIA

Show how you have connected the PIR and Buzzer to the Arduino.

In your loop, if the PIR detects any movement, it turns on the buzzer. so if it's on your desktop right in front of you, it will never stop buzzing. Put a paper cup over the PIR. Does it stop now?

Hi royanc,

I would use tone and noTone commands instead of digitalWrites.

This link shows you the basics of how to use "Tone" and "noTone" commands:

If you want the buzzer to continually beep until a noTone command change

tone (Buzzer, 1000);

To

tone (Buzzer);

This will continually beep until it is given a noTone command:

noTone (Buzzer);

You can also change the pitch of the beep using tone commands.

Hope this helps!

Zeb

ZebH:
Hi royanc,

I would use tone and noTone commands instead of digitalWrites.

This link shows you the basics of how to use "Tone" and "noTone" commands:
https://www.instructables.com/id/How-to-use-a-Buzzer-Arduino-Tutorial/

If you want the buzzer to continually beep until a noTone command change

tone (Buzzer, 1000);

To

tone (Buzzer);

This will continually beep until it is given a noTone command:

noTone (Buzzer);

You can also change the pitch of the beep using tone commands.
tone() - Arduino Reference

Hope this helps!

Zeb

it's working after few changes..
thank you very much

No problem! Glad it's working!

Zeb