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
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
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)
#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);
}
}