// alarm code: copywrite Series2software Ltd
int buttonPin = 4; // the number of the pushbutton pin - door switch Low = shut, High = Open
int relayPin = 13; // for the siron
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
//initialize the relay pin as an output:
pinMode(relayPin, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
// siren will beep twice to confirm the alarm is on
digitalWrite(relayPin, HIGH); // turn the siren on (HIGH is the voltage level)
delay(50); // wait for a 1/2 second
digitalWrite(relayPin, LOW); // turn the siren off by making the voltage LOW
delay(50); // wait for a 1/2 second
digitalWrite(relayPin, HIGH); // turn the siren on (HIGH is the voltage level)
delay(50); // wait for a 1/2 second
digitalWrite(relayPin, LOW); // turn the siren off by making the voltage LOW
// 15 second start delay
Serial.println("hello Steve");
Serial.println("Two beeps to confirm the alarm has be turned on");
delay(15000);
// siren will beep once after 15 seconds to confirm the alarm is set
Serial.println("One beep to confirm that the alarm is active");
digitalWrite(relayPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a 1/2 seconds
digitalWrite(relayPin, LOW); // turn the LED off by making the voltage LOW
Serial.println("Start loop");
Serial.println("waiting for the door to open");
Serial.println("door has been opened");
//while the door is shut
while (digitalRead(buttonPin) == HIGH) {
// siren loop counts 15 times
Serial.println(digitalRead(buttonPin)); //you should see lots of 1's until you presslet go of the button
}
Serial.println("door has opened");
//wait for 10 seconds after the door is openned allowing time to get into the car and shutting off the system
delay(10000);
// for (int doorLoop = 0; doorLoop < 6; doorLoop++)
Serial.println("door has been open for 10 seconds start the alarm");
// raise the alarm for 4 iterations
for (int alarmLoop = 0; alarmLoop < 4; alarmLoop++)
{
// Serial.println("alarm loop");
Serial.println("alarmLoop"); //you should see 0,1,2,3
Serial.println(alarmLoop); //you should see 0,1,2,3
// raise the alarm for 1 min
for (int sirenLoop = 0; sirenLoop < 16; sirenLoop++) {
Serial.println("siren loop");
Serial.println(sirenLoop); //you should see 0,1,2,3...15
//Siron on for 1 second then siren off for 1 second
digitalWrite(relayPin, HIGH); // turn the siren relay ON
delay(1000); // wait for a second
digitalWrite(relayPin, LOW); // turn the siren relay OFF
delay(1000); // wait for a 1 second
}
// silent of 1 min
Serial.println("Silent for 1 min");
delay(60000); // change time from 60000
}
// silence the alarm for 5 days
Serial.println("Silent for 5 days");
// if the door is shut nothing will happen otherwise the alarm will go off again for 3 mins
Serial.println("wait for 5 days before starting all over again");
// 5 days = 120 loops x 3,600,000 milliseconds
for (int silenceLoop = 0; silenceLoop < 120; silenceLoop++)
{
Serial.println("silenceLoop"); //you should see 0,1,2,3 hours
Serial.println(silenceLoop); //you should see 0,1,2,3 hours
Serial.println("hours silent");
delay(3600000); // wait for 1 Hour
}
}