-1
\$\begingroup\$

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); } 
\$\endgroup\$
8
  • 1
    \$\begingroup\$ Is the output-pin of the PIR-Sensor high? Do you have a multimeter to measure the voltage at this pin from the sensor? \$\endgroup\$ Commented Sep 10 at 19:52
  • 1
    \$\begingroup\$ The code should be 100% correct - but we don't know which sensor it is, how it works, how you connected it and to which pin, or is there a misplaced or broken wire. A pin that idles and stays high will constantly keep beeping as per your code. \$\endgroup\$ Commented Sep 10 at 19:54
  • \$\begingroup\$ As I said I am new so that I don't have multi meter however I can guarantee that the connection is correct as I have stated and there is no broken wire. It is a pir motion sensor module, Example image of Sensor \$\endgroup\$ Commented Sep 10 at 20:12
  • \$\begingroup\$ @AlsiroMira - You can use a resistor and a LED to show that the pin is high. A white LED need at least 2.4 Volt (extremely dim) till 2.9V (very bright) to lit up. \$\endgroup\$ Commented Sep 10 at 22:20
  • \$\begingroup\$ @MikroPower i don't wanna use led, as I have the buzzer to make sound when motion and silent when I motion but the issue is it's all the time is logging, "Motion detected". \$\endgroup\$ Commented Sep 11 at 7:59

1 Answer 1

1
\$\begingroup\$

But the problem is it constantly beeps

This is the correct behaviour because you set the pin with pull-up pinMode(inputPin, INPUT_PULLUP); so it is always HIGH by default.

Based on the link that you provided for the PIR control board, I would guess that you have the sensor same or identical to this one, which actually has a pull-down resistor.

PIR sensor block diagram

So all you need to change is

pinMode(inputPin, INPUT); 

The rest of the code remains the same. Let us know if this works?

\$\endgroup\$
5
  • \$\begingroup\$ It doesn't work. I encounter the same issue as before. \$\endgroup\$ Commented Sep 11 at 7:52
  • \$\begingroup\$ And is there a way I could know whether my pir motion sensor outputs, voltage on detection or put the pin low. The image has attached because it looked so much identical, to what I have. \$\endgroup\$ Commented Sep 11 at 12:56
  • \$\begingroup\$ Use a multimeter to confirm whether there is a pull-up or pull-down resistor and what is the resistor value. Connect a 5V between VCC and GND and measure output to see is there any change when there is an object in front and without. The link that I provided has all the information you need, read it. \$\endgroup\$ Commented Sep 12 at 7:39
  • \$\begingroup\$ On the comment "It doesn't work", did you try to adjust the trimmers to adjust the sensitivity and delay? \$\endgroup\$ Commented Sep 12 at 7:41
  • \$\begingroup\$ Indeed, Yes I tried. \$\endgroup\$ Commented Sep 12 at 9:28

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.