PIR sensor

I have built a circuit and copied the program in this website.

However, it doesn’t work. The buzzer is always active although nothing is detected. Is the sensor too sensitive?
I do not familiar with programming. Is the program OK?
My PIR sensor model is 555-28027-ND.
Thanks for your help.

int ledVermelho = 8; // Pin to the red LED (RED)
int ledVerde = 7; // Pin to the green LED (Green)
int piezoPin = 6; // Pin to the + PIEZO

int PIRPin = 4; // OUT pin of the RIP (reading value)
int botaoPin = 5; // read the input pin Button

int PIR= 0; // Variable that represents the value provided by PIR sensor
int Bot = 0; // Variable that represents the value provided by Button

void setup () { // Declare as LEDs and piezo pins RIP Output as Input and Button
pinMode (piezoPin, OUTPUT);
pinMode (ledVermelho, OUTPUT);
pinMode (ledVerde, OUTPUT);
pinMode (PIRPin, INPUT);
pinMode (botaoPin, INPUT);
}

void somAlerta() { // Function name: "somAlerta that generates beep
digitalWrite (piezoPin, HIGH);
delayMicroseconds (600);
digitalWrite (piezoPin, LOW);
delayMicroseconds (600);
}

void piscaLED(){ // Function name: "piscaLED that generates beep

digitalWrite (ledVerde, LOW); // pin will be Land ledVerde
digitalWrite (ledVermelho, HIGH); // Red LED ON
delay (100);

digitalWrite (ledVermelho, LOW) ; // Red LED OFF
delay (100);
}

void loop () {

PIR = digitalRead(PIRPin); // Reads the RIP OUT-sense and plays in the variable value read: “RIP”

if (PIR == HIGH) { // Test if the variable “RIP” is high (5v), if YES: If a task executes NOT skip else {

do { // Do this task and test while
digitalWrite (ledVermelho, HIGH); // Red LED League
digitalWrite(ledVerde, LOW); // Green LED pin becomes the GND (ground) led the Red
somAlerta(); // call function that will sound an alert

Bot = digitalRead(botaoPin); // Reads the play button and the value in variálvel “Bot”

} while(Bot==0); // While the variable is zero Bot (button not pressed) to continue running

}
else{ // RIP is not HIGH then performs the tasks that are on else {
if (Bot==1){ // if the button is pressed after the alarm goes off to do a task
for (int i=0;i<5; i++){ // Timer (few seconds) that the function will be called “piscaLED ()”
piscaLED(); // call function that flashes the red LED
}

digitalWrite (ledVermelho, LOW);
digitalWrite (ledVerde, HIGH); // Green LED for Power
delay (10000); // Wait 10 seconds (prevents a new alarm immediately)

Bot=0; // After calling the timer function and run pescaLED declares that the variable “BOT” is zero
}

digitalWrite (ledVermelho, LOW); // Holds the pin as Red GND (ground) for the lede GREEN
digitalWrite (ledVerde, HIGH); // Green LED ON

}

}

Is the program OK?

No, it is far too complicated. You need to simplify it, to simply print the state of the input pin.

Hook the red LED to D4 (the PIR pin) instead of D8 (the Red LED pin) and you will be able to tell if the PIR sensor is signaling HIGH or LOW.

If the signal is HIGH all the time, that would explain why the alarm is on all the time.

johnwasser: Hook the red LED to D4 (the PIR pin) instead of D8 (the Red LED pin) and you will be able to tell if the PIR sensor is signaling HIGH or LOW.

If the signal is HIGH all the time, that would explain why the alarm is on all the time.

Then the PIR sensor should be hooked to ...... ?

carr823:

johnwasser: Hook the red LED to D4 (the PIR pin) instead of D8 (the Red LED pin) and you will be able to tell if the PIR sensor is signaling HIGH or LOW.

If the signal is HIGH all the time, that would explain why the alarm is on all the time.

Then the PIR sensor should be hooked to ...... ?

...the same pin. The input pin and the LED will both be controlled by the output of the PIR. This is just to see if your PIR is turning the output on and off as you expect.