Motion sensor alarm

Hi,

I am wanting to make a motion sensor alarm for my driveway. I have a arduino board, 4 wire pir sensor and a 2x piezo buzzers...

This is my first project, can anyone point me in the right direction for programming these to work making it beep 3 times, giving some cool down time and also altering the motion sensors sensitivity if possible?

Thanks

Adafruit has a PIR sensor tutoria:

Thanks, does the tutorial stand true if using a generic motion sensor?

Cheers

Don't know, never used a PIR. But, it's a start.

I am wanting to make a motion sensor alarm for my driveway.

Why? Is your driveway moving on you?

can anyone point me in the right direction for programming these

I've never seen a programmable PIR sensor or a programmable piezo buzzer, so, no. Programming the Arduino is a different story, but programming it requires having some idea which devices are connected to which pins AND a set of requirements for the code.

giving some cool down time

What is getting hot, that needs to cool down?

altering the motion sensors sensitivity

That is a hardware setting, not something you code.

lol..

This concept is clearly not to sense the driveway itself... It is to detect motion of people walking/driving into our driveway so we get an alert (buzz) inside of our home.

The cool down time is what I understand the ability for the motion sensor to not register motion within say 30 seconds of the last detection.

Anyway moving on!

I have it setup, but not sure its working correctly as getting a bit of inconsistent buzzing..

Part list:

Uno r3
12volt piezo buzzer
12volt Dual element PIR detector

The arduino is connected to a 12volt power supply and the PIR detector is connected to the same 12volt power supply..

The PIR has 2 zone connectors.. When I use one zone wire to pin 2 the piezo seems to go off constantly even without motion, but if I connect the 2nd zone wire to ground I get a better response but buzz pattern seems inconsistent..

should I be connecting the 2nd zone wire to ground to complete the circuit?

here is the code:

// Uses a PIR sensor to detect movement, buzzes a buzzer
// more info here: http://blog.makezine.com/projects/pir-sensor-arduino-alarm/
// email me, John Park, at jp@jpixl.net
// based upon:
// PIR sensor tester by Limor Fried of Adafruit
// tone code by michael@thegrebs.com


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;                    // variable for reading the pin status
int pinSpeaker = 10;           //Set up a speaker on a PWM pin (digital 9, 10, or 11)

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
  pinMode(pinSpeaker, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    playTone(300, 160);
    delay(150);


    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    playTone(0, 0);
    delay(300);
    if (pirState == HIGH) {
      // we have just turned off
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}
// duration in mSecs, frequency in hertz
void playTone(long duration, int freq) {
  duration *= 1000;
  int period = (1.0 / freq) * 1000000;
  long elapsed_time = 0;
  while (elapsed_time < duration) {
    digitalWrite(pinSpeaker, HIGH);
    delayMicroseconds(period / 2);
    digitalWrite(pinSpeaker, LOW);
    delayMicroseconds(period / 2);
    elapsed_time += (period);
  }
}

Cheers

kronicnz wrote (in part):

should I be connecting the 2nd zone wire to ground to complete the circuit?

How could anyone answer this if you have not told us the Manufacturer and the Model Number of the PIR sensor? A link to data on the PIR sensor would be even better.

You told us how the Arduino and the PIR sensor are connected, but you told us nothing about the "12volt piezo buzzer".

Also, in the future...

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.
  4. If you already posted without code tags, you may add the code tags by
    editing your post. Do not change your existing posts in any other way.
    You may make additional posts as needed.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.

Good Luck!