Alarmsystem based on Arduuino Micro

Hi All,

I'm building an alarm system based on an arduino micro. It's my first serious arduino project and as I go along I'm facing some challenges.

In this first post I would like to introduce my system and let you know how far I got. In follow up messages I would like to ask questions about the challenges I'm facing as I go along.

I will (try to) update this opening post every time I solve a piece of this puzzle.

So far my system, as explained below, works :slight_smile:

My basic goal features (in random order) for now are:

CH : implemented in both code and hardware
Ch : implemented in code but not in hardware
ch : not implemented in code nor hardware

CH - PIR sensor to detect motion
CH - keypad, 5 digit code to arm/disarm system
CH - piezo beeps to give feedback about input and status change
CH - red and green status leds
CH - if the user forgets to arm, automatically arm after X minutes

Ch - if the system is armed and motion is detected: a siren will sound and lights will flash for X seconds

ch - if the system is not armed and motion is detected: switch on regular tubelight
ch - turn of regular tubelight when the system is armed

Minor code functionality is mentioned and commented in the code

The system (so far) consists of:

Libraries used:

My code so far is this:

Ok,

so my next challenge is about a timeout:

  • if a user forgets to arm the system
  • AND no motion is detected for X minutes
  • the system should arm automatically

I think I can use the simpletimer library : Arduino Playground - SimpleTimer Library

EDIT:

I couldn't figure how to use simpletimer :s

So I ended up using stopwatch:
http://playground.arduino.cc/Code/StopWatchClass

And it works :slight_smile:

Hi all,

I'm having trouble with my PIR motion sensor:

I set the sensitivity to 25%

It keeps giving false positives. To test what the issue might be I put the sensor into a cardboard box and wrote a test program (see code below).

This is the circuit:

In the table below 30 random false positives are recorded with the time in seconds.
Also the time between show they occur randomly

What could be the problem here ? If it is unreliable I will have to look for an alternative sensor to detect motion. I was thinking about an ultrasonic range detector.

Or does anyone have a better suggestion ?

column 1: false positive #
column 2: the time it occured (seconds)
column 3: the time since last false positive (seconds)

1		264		
2		324		60
3		449		125
4		507		58
5		864		357
6		1668		804
7		2015		347
8		2664		649
9		3422		758
10		3696		274
11		4300		604
12		4464		164
13		5376		912
14		6264		888
15		7057		793
16		7842		785
17		8064		222
18		8308		244
19		8738		430
20		8831		93
21		8893		62
22		9864		971
23		9926		62
24		10419	493
25		10622	203
26		11664	1042
27		11965	301
28		12208	243
29		12265	57
30		12424	159

The program I used to test the PIR:

#include <StopWatch.h>

//===========================================================
//SETUP COMPONENTS ==========================================

//PIR sensor
#define pinPir 2    //PIR sensor output

////piezo buzzer
#define pinPiezo 3

// Status leds
#define ledGreen 4
#define ledRed 5


//PIR SENSOR VARS ===================================================
//the time we give the sensor to calibrate (30-60 secs for ADA-189)
int calibrationTime = 45;


StopWatch stwTrack(StopWatch::SECONDS);


/////////////////////////////
//SETUP
void setup() {

  Serial.begin(9600);

  //setup pir sensor
  pinMode(pinPir, INPUT);
  digitalWrite(pinPir, LOW);

  //setup leds
  pinMode(ledRed, OUTPUT);
  digitalWrite(ledRed, LOW);

  //give the sensor some time to calibrate
  Serial.println("calibrating sensor ");
  for (int i = 0; i < calibrationTime; i++) {
    Serial.println(calibrationTime - i);
    delay(1000);
  }
  Serial.println(" done");
  Serial.println("SENSOR ACTIVE");
  delay(50);
  }


////////////////////////////
// MAIN LOOP

void loop() {

      //if the stopwatch is not running, start it
      if(stwTrack.isRunning() == 0){
        stwTrack.start();
      }

      //check the PIR input
      if (digitalRead(pinPir) == HIGH) {
        
        tone(pinPiezo, 1000);
        delay(500);
        noTone(pinPiezo);
        digitalWrite(ledRed, HIGH);
        Serial.println(stwTrack.elapsed());   //print the time 
        delay(7000);                          //wait for the PIR to go low
        digitalWrite(ledRed, LOW);
      }
  
}