I have a active buzzer and a PIR motion sensor and an Arduino board.
While I try to achieve, when there is motion then a buzzer to make the beep sound and between each motion to be a delay.
But the problem is it constantly beeps and when I see the serial monitor I see, although there is no motion.
Motion Detected raw pin value: 1 Here are my connection (I am new to this Arduino).
For PIR Sensor:
PIR Sensor VCC = 5V PIR Sensor GND = GND PIR Sensor OUT = D2 And for Buzzer:
Buzzer (+) = D8 Buzzer (–) = GND And this is the code:
int buzz = 8; int inputPin = 2; int val = 0; void setup() { pinMode(buzz, OUTPUT); digitalWrite(buzz, LOW); // enable internal pullup pinMode(inputPin, INPUT_PULLUP); Serial.begin(9600); Serial.println("Function pin is called"); } void play_tone() { digitalWrite(buzz, HIGH); delay(1000); digitalWrite(buzz, LOW); delay(1000); } void loop() { val = digitalRead(inputPin); if (val == HIGH) { Serial.println("Motion detected!"); play_tone(); } else { digitalWrite(buzz, LOW); Serial.println("Motion ended!"); } val = digitalRead(inputPin); Serial.print("raw pin value: "); Serial.println(val); delay(500); } 