I have used PIR motion sensor with arduino Uno r3, alongwith one piezo buzzer. and the program is as
/*
* PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0;
int piezoPin = 11;
// variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT);
pinMode(piezoPin, OUTPUT);
Serial.begin(9600);
// declare sensor as input
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH);
tone(piezoPin,300,160);
delay(150);
// turn LED ON
if (pirState == LOW) {
// we have just turned on
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW);
tone(piezoPin,0,0);
delay(300);
// turn LED OFF
if (pirState == HIGH){
// we have just turned of
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
but it supposed to ring buzzer at the time of pir motion sensor getting signal. But buzzer continuously ringing and at the time of pir sensor getting signal, it just ring louder. What is the problem in program``