Project tutorial
Arduino Wireless Alarm System Using Existing Sensors

Arduino Wireless Alarm System Using Existing Sensors © CC BY-SA

A cheap and effective replacement for a GSM alarm still using the existing commercial 433Mhz wireless alarm sensors.

  • 8 views
  • 0 comments
  • 0 respects

Components and supplies

Apps and online services

About this project

This project can be built in about half an hour at a cost of about $20.00 if you have existing 433Mhz or 315Mhz wireless alarm sensors.

It can also be a complete new project with wireless alarm sensors, such as infrared motion detectors and reed switches, easily and cheaply available online. Just search for 433Mhz or 315Mhz sensors that use PT2262 or EV1527 coding.

I am sure there are many people like me who have purchased a GSM/2G alarm system with wireless sensors and were happy with it, however when the 2G/GSM network was turned off where I live, I was left with an alarm system I could no longer program or even set the time on it. One day while wondering what I could do to make my alarm functional again, it occurred to me to check if an Arduino could receive signals from the sensors. I stumbled across an instuctable https://www.instructables.com/id/Decoding-and-sending-433MHz-RF-codes-with-Arduino-/ and after some experimenting determined that I could receive the signals from my existing sensors. I began the process to build an alarm system that could replace my existing alarm and would also provide increased functionality. One of the issues with the old alarm was never actually knowing exactly which of the 25 sensors went off, by adding an LCD screen to my new alarm build I now get text on the LCD indicating exactly which sensor was activated. The new alarm can still be manually armed by my existing wireless keyfobs and has a real time clock to allow it to automatically arm and disarm at preset-able times of the day.

Supplies:

See additional notes at end to ensure you use the correct version of these parts.

Arduino Uno or similar

433 or 315 MHz receiver module for Arduino

DS3231 Real Time Clock module for Arduino

I2C 16x2 LDC module for Arduino

Wireless Alarm reed switches, motion sensors and remote key fobs as desired

Piezo buzzer

LED & 220 ohm resistor

Breadboard (optional but recommended)

Suitable power supply for Arduino

Jumper wires etc

PC with Arduino IDE installed

Basic knowledge of Arduino

Step 1: Wire Up the Ardunio and Modules As Shown in the Image

file:///home/samba/transfers/frizting.png

Piezo between pin 5 of the Arduino and earth

LED between pin 8 of the Arduino and to a 220ohm resistor then to earth

433 or 315 Mhz receiver, VCC to 5V, GND to ground and either one of the 2 data pins to pin2 of the Arduino

I2C 16X2 LCD Module VCC to 5V, GND to ground, SCL SDA pins to SCL SDA of the Arduino (pin A5 is SCL, pin A4 is SDA)

DS3231 RTC Module VCC to 5V, GND to ground, SCL SDA pins to SCL SDA of the Arduino (there is 2nd set located above the GND and AREF pins of most Arduino's)

I know some of you will not need anymore info than this and the sketch attached below but I will go into some more detail for anyone who would like a little further assistance.

Step 2: Add Necessary Libraries to the Arduino IDE

The Arduino Sketch to run the alarm uses some libraries that are not already installed on the Arduino IDE by default.

To add RCSwitch library to the Arduino IDE. Open the Arduino IDE in the top menu select "Sketch" then from the drop down select "Include library" and from the next drop down select "Manage libraries". Then in the "Filter your search" box type "RCSW", next click on install for "rc-switch by sui77"

Detailed instructions on adding libraries at https://www.arduino.cc/en/guide/libraries

While we are at it we also need to add the libraries called Time, TimeAlarms, DS1307RTC and LiquidCrystal_I2C, same procedure as above but searching for the name of each new library and installing.

The DS3231 real-time clock is compatible with and uses the DS1307RTC library.

Step 3: Next We Need to To Get the Codes for Your Sensors

I have provided the template of the Arduino code below but you will need to find the values for each of your sensors and paste them into the code.

There is extensive information on how to obtain these codes at both these sites;

https://www.instructables.com/id/Decoding-and-sending-433MHz-RF-codes-with-Arduino-/

https://github.com/sui77/rc-switch/wiki

However here is my abbreviated version;

To obtain the codes your sensors and remote key fobs are sending, attach the Arduino as assembled in step 1 to a PC via USB cable and open the Arduino IDE. Then in the Arduino IDE go to the "File" drop down, then go to "Examples" scroll down the list of example sketches until you find "RCSWITCH" then select the "ReceiveDemo_Advanced" sketch and upload it to the Arduino. Once the sketch successfully uploads open the serial monitor of the Arduino IDE with it still attached to your PC via USB. Now trigger the first of the sensors you want to get the code for, the output from RCSwitch will appear in the serial monitor window. For this project we are looking for the decimal codes as highlighted in the screenshot below. You will need to trigger the sensor multiple times looking for the decimal value that appears most often, sometimes there will be different values mixed in with true value, this is caused by interference from random radio waves or other devices operating on same frequency.

file:///home/samba/transfers/codes.png

Note the decimal code of the sensor for use in the next step. Repeat for all the sensors and remote keyfobs you want to use in the project, keeping track of which code goes with which sensor. If using keyfobs to arm and disarm the alarm you will need note the different codes for the arm button and the disarm button of each remote.

Step 4: Arduino Code Template

Below is a copy of my Arduino code as a.ino file called Wireless_Alarm. You can click on it and it should open in the Arduino IDE. I am not a programmer my code is assembled in part from the examples found in the Arduino IDE, it is probably not particularly elegant but it does work and has been reliable over a long period of time.

Remember to re-save the sketch after you make the changes to include the codes from your own sensors.

Step 5: Paste the Codes You Obtained in Step 5 Into the Template Arduino Sketch.

Now the steps to customize the code for the sensors and remote keyfobs you are using.

If you open the Wireless_Alarm sketch in your IDE you will see at line 111.

if (mySwitch.getReceivedValue() == 115166236) //Fob arm button code

Where in the existing code it reads 115166236 you need replace that number with decimal code for the arm button of your remote keyfob which you recorded at Step 5.

For example if in step 5 you got a decimal 1154321 you would modify line 111 to now read;

if (mySwitch.getReceivedValue() == 1154321) //Fob arm button code

Follow the same procedure for line 125.

if (mySwitch.getReceivedValue() == 115166234)  //Fob disarm button code

Substitute 115166234 for the code of your remote keyfob disarm button which you recorded at Step 5.

If you want to use multiple remote fobs to arm and disarm, copy and paste lines 111 through to 136 as many times as required then change values to suit your other remote keyfobs, but best just to start with one remote until you are sure your modified sketch is working.

Now to coding the alarm sensors in the sketch at line 140

if(ledState == HIGH && mySwitch.getReceivedValue() == 1151640) //Action for signal sender office cupboard

Take out 1151640 and insert the decimal value of one of your alarm sensors.

Then at line 158.

lcd.print(F("Office cupboard")); //print message to lcd to know which sensor was activated (and go and find the burglar :)

Change Office cupboard to what ever you would like to be displayed on the LCD for that sensor. For example if you want it to read kitchendoor make the line look like this;

lcd.print(F("Kitchendoor")); //print message to lcd to know which sensor was activated (and go and find the burglar :)

Names should not exceed 16 characters.

Between line 165 and 187 is a template to copy and paste as many times as required to the lines directly below 187. Replace the number after mySwitch.getReceivedValue() == with the decimal of one of your other sensors that you recorded in step 5 and change name within the " " in lcd.print(F("sensornamehere")); to the name you want to give your sensor.

If you are not using remote keyfobs to arm and disarm your alarm you can just ignore lines 111-136 or put // at the start of each of the unwanted lines and the Arduino will not read them.

Remember to save the file after you have made your changes.

Step 6: Upload the Amended.ino to Your Arduino and Test.

With the Arduino still connected to your PC by USB upload the sketch to the Arduino Board. Once the upload is successfully completed the LCD should read "Alarm On Disarmed". Push the arm button on your remote and the LCD should read "Alarm On Armed" and the LED should be lit to let you know it is armed, now trigger a sensor while it is armed, LCD should read Alarm follow by a time stamp and the location of the sensor, the beeper should sound for 2 minutes unless you push the disarm button. If you are not getting this result recheck the codes you got in Step 5 and the changes you made to the code in the previous step, also recheck the wiring of all components. If the LCD is not reading at all, there is a contrast adjustment on the back of the LCD module. Once contrast is set correctly if the LCD is still not reading try changing the Address of the LCD from 0x3f to 0x27 at line 12 in the sketch. LCD troubleshooting here I2C LCD tutorial

Step 7: Setting the Time on RTC Module and Changing the Arm and Disarm Times

Hopefully your RTC was already set with the correct time but if not open the IDE, select 'File" and from the dropdown click on "Examples", scroll down to "DS1307RTC" and select the "SetTime" sketch, download the sketch to your Arduino and it will set the real time clock with the time from your PC. You will then need to reload the Wireless_Alarm sketch to your Arduino.

The Wireless_Alarm.ino I have provided will by default set the alarm to arm automatically at 10.15pm every night and disarm at 6.00am each morning. To change these times, modify the Sketch at lines 71 and 72. The time is in brackets after Alarm.alarmRepeat in the format HH, MM, SS. change this to whatever time suits you.

Alarm.alarmRepeat(6,00,0,MorningAlarm);  // DISARM time
Alarm.alarmRepeat(22,15,0,EveningAlarm);  // ARM time

So to change the disarm time to 9.15am and the arm time to 5.30pm the code would look like this

Alarm.alarmRepeat(9,15,0,MorningAlarm);  // DISARM time
Alarm.alarmRepeat(17,30,0,EveningAlarm);  // ARM time

If you do not want the alarm to arm and disarm automatically put // in front of the 2 lines and they wont be used.

//Alarm.alarmRepeat(6,00,0,MorningAlarm);  // DISARM time
//Alarm.alarmRepeat(22,15,0,EveningAlarm); //Arm time

The time the alarm beeper sounds for can be changed by modifying line 20

const long interval = 120000; //for millis delay for length of time alarm sounds

The interval is in milliseconds so 120000 = 120 seconds, changing 120000 to 30000 would make the alarm sound for 30 seconds.

A solenoid to run a siren, strobe light, high volume beeper etc can be also be wired to pin 7 or pin 9 and will run for the "interval" as set above. Bear in mind the maximum load for an Arduino pin should not exceed 40mA.

Additional Notes

When selecting a 433 or 315 MHz receiver module for Arduino you should pick the frequency to match the alarm sensors you intend to use. I suggest buying a module that comes with a small spiral helical antennae for best performance, alternatively a 17.3mm long straight wire antennae also increases performance.

With the 16x2 LCD module you must use a 4 pin I2C LCD to use the instructions and code I provide here, it could be made with a 16 pin standard LCD but it will not work with the wiring or code here.

Wireless alarm reed switches, motion sensors and remote key fobs should be 433Mhz or 315Mhz to match with the receiver you intend to use and should use PT2262 or EV1527 coding.

The alarm is expandable and adaptable, I have already added an SD card to record when sensors are triggered, modified the LCD to only be lit when a button is held and added a 100dB siren, but have not included details here to keep the article as short and simple as possible. I hope sharing the work I have done on this alarm is of some use to others.

Happy to answer any questions.

Thanks.

Code

Wireless_Alarm.inoArduino
////Written by fourblackmans 10/6/2018

#include <RCSwitch.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>  


RCSwitch mySwitch = RCSwitch();// initialise RCswitch function to recieve signals from  the 433Mhz senders   
LiquidCrystal_I2C lcd(0x3f, 16, 2);  // set the LCD address to 0x27 or 0x3f for most 16x2 lcd's

const int ALARM = 7;  // used to have a LED on pin 7 to indicate sender triggered while alarm armed can also be used fora solenoid
const int LED = 8; //Alarm armed LED
const int ALARM2 = 9;   /// pin 9 can have soleniod connected to action siren if sender triggered while alarm armed

int ledState = LOW;  //Start in Disarmed state
int alarmState = LOW; // Start with alarm state as alarm not triggered

unsigned long previousMillis = 0; //for millis delay for length of time alarm sounds
const long interval = 120000; //length of time alarm sounds
unsigned long currentMillis = 0; //for millis delay for length of time alarm sounds

unsigned long previousMillis2 = 0;// for millis delay time serial print
const long interval2 = 1000;         // for millis delay time serial print

const byte speakerPin=5;  // Pin 5 for piezo buzzer
unsigned long lastPeriodStart;// For beeper
const int onDuration=500;// For beeper
const int periodDuration=700;// For beeper



void setup(){
  
  mySwitch.enableReceive(0);  //Myswitch waiting for 433mhz signals from senders
  pinMode(8, OUTPUT);// Alarm Armed indicator led
  pinMode(13, OUTPUT); //turn Arduinos onboard led on 13 off (because it is too bright at night:)
  pinMode(7, OUTPUT);  // Alarm triggered LED
  pinMode(9, OUTPUT); //Alarm triggered soloniod
  digitalWrite(LED, LOW);  //Start with armed LED off
  digitalWrite(ALARM, LOW);  //start with alarm LED off
  
  


  lcd.init();                      // initialize the lcd 
 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print(F("Alarm ON"));
  lcd.setCursor(0,1);
  lcd.print(F("Disarmed"));
   
//RTC section
Serial.begin(9600);
  // wait for Arduino Serial Monitor
  while (!Serial) ; 
  // get and set the time from the RTC
  setSyncProvider(RTC.get);   //get the time from RTC
  if (timeStatus() != timeSet) 
     Serial.println(F("Unable to sync with the RTC"));
  else
     Serial.println(F("RTC has set the system time"));     
   // to test your project, you can set the time manually 
   // setTime(22,14,55,1,1,11); // set time to 22:14 and 55 seconds on 1 Jan 2011

  // create  arm and disarm events  at specific times
  Alarm.alarmRepeat(6,00,0,MorningAlarm);  // DISARM time
  Alarm.alarmRepeat(22,15,0,EveningAlarm);  // ARM time

}


void loop(){

//RTC section
  {

  Alarm.delay(1); //Must be present for TimeAlrams to work
}

unsigned long currentMillis2 = millis();    //This section delays print time to serial to only once per second

  if (currentMillis2 - previousMillis2 >= interval2) {
    digitalClockDisplay();
    previousMillis2 = currentMillis2;
     }



  
if (alarmState == LOW)          //This section sounds buzzer without using delay command
{ lastPeriodStart = millis();}    
 if(alarmState == HIGH) //if sender is triggered the alarm state is set high and sounds the buzzer while alarm remains high (this is set for 120000 millis)
  {if (millis()-lastPeriodStart>=periodDuration)
  {lastPeriodStart+=periodDuration;
    tone(speakerPin, 1000, onDuration); // play 1000 Hz tone in background for 'onDuration'
 }
  }

if(alarmState == HIGH) {digitalWrite(ALARM2, HIGH);} //If alarm triggered make alrm solonoid pin (9) high

if(alarmState == LOW) {digitalWrite(ALARM2, LOW);}   //If alarm not triggered make alarm solonoid pin (9)low




if (mySwitch.getReceivedValue() == 1151636) //Fob arm button code
    {  ledState = HIGH;                  //if code is received set alarm state to armed
       digitalWrite(LED, HIGH);         // Turn on the alarm armed led
       tone(speakerPin, 1500);delay(100);noTone(speakerPin);delay(50); //Beep when Arming
       tone(speakerPin, 1500);delay(100);noTone(speakerPin);delay(50); 
       Serial.println(F("ON"));
       lcd.clear();
       lcd.setCursor(0,0); //Start at character 0 on line 0
       lcd.print(F("Alarm On"));
       lcd.setCursor(0,1);
       lcd.print(F("Armed")); }

       
    
if (mySwitch.getReceivedValue() == 1151634)  //Fob disarm button code
    { ledState = LOW;   //if code is received set alarm state to disarmed
      digitalWrite(LED, LOW);     //Turn off the alarm led
      Serial.println(F("OFF"));
      digitalWrite(ALARM, LOW);
      alarmState= LOW;
      tone(speakerPin,1500);delay(100);noTone(speakerPin);delay(50); //beep when disarming
      lcd.clear();
      lcd.setCursor(0,0); //Start at character 0 on line 0
      lcd.print(F("Alarm On"));
      lcd.setCursor(0,1);
      lcd.print(F("Disarmed")); }
 
 
    
if(ledState == HIGH && mySwitch.getReceivedValue() == 1151640)  // if the alarm is armed and this code is received do this
    {    
     digitalWrite(ALARM, HIGH);    //turn on the alarm solonoid pins
     alarmState = HIGH;            //Set the alarm state to alarm going off
     lcd.clear();
     lcd.setCursor(0,0); //Start at character 0 on line 0
     lcd.print(F("Alarm"));   //print message to lcd to know which sensor is was activated (and go and find the burglar :)
     lcd.setCursor(7, 0);  // PRINT hour to LCD
     if (hour() < 10)             
     lcd.print(F("0"));
     lcd.print(hour());
     lcd.setCursor(9, 0);
     lcd.print(F(":"));
     lcd.setCursor(10, 0);// PRINT minutes to LCD
     if (minute  () < 10)
     lcd.print(F("0"));
     lcd.print(minute());
     lcd.setCursor(0,1);
     lcd.print(F("Office cupboard")); //print message to lcd to know which sensor was activated (and go and find the burglar :)
 
  
  } 

  
  
if(ledState == HIGH && mySwitch.getReceivedValue() == 12345678) //Action for sender Office window
  {     // if the alarm is armed and the the 433mhz code above is received do this
     digitalWrite(ALARM, HIGH);    //turn on the alarm solonoid pins
     alarmState = HIGH;            //Set the alarm state to alarm going off
     lcd.clear();
     lcd.setCursor(0,0); //Start at character 0 on line 0
     lcd.print(F("Alarm"));   //print message to lcd to know which sensor was activated (and go and find the burglar :)
     lcd.setCursor(7, 0);  // PRINT hour to LCD
     if (hour() < 10)             
     lcd.print(F("0"));
     lcd.print(hour());
     lcd.setCursor(9, 0);
     lcd.print(F(":"));
     lcd.setCursor(10, 0);// PRINT minutes to LCD
     if (minute  () < 10)
     lcd.print(F("0"));
     lcd.print(minute());
     lcd.setCursor(0,1);
     lcd.print(F("sensornamehere"));  //print message to lcd to know which sensor is was activated (and go and find the burglar :)
 
  
  } 
  

 

  
    
unsigned long currentMillis = millis();   //This section allows the alarm state and alarm led to remain on for a set period
  if(alarmState == LOW) {previousMillis = millis();}

  if (currentMillis - previousMillis >= interval) {
     previousMillis = currentMillis;
    // if the alarm state and alarm led is on turn it off:
         alarmState = LOW;
      digitalWrite(ALARM, LOW);
   }

  mySwitch.resetAvailable(); 
     Alarm.delay(50);//for stability
  
}
///Section for functions

// functions to be called at certain times of day

// Disarm the alarm in the moring from RTC
void MorningAlarm() {
  // write here the task to perform every morning
  Serial.println(F("Disarmed"));
  digitalWrite(LED, LOW);  //turn the armed led off
  ledState = LOW;//  disarm the alarm
       lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print(F("Alarm On"));
  lcd.setCursor(0,1);
  lcd.print(F("Disarmed"));
}
//Arm the alarm at night from RTC
void EveningAlarm() {
  // write here the task to perform every evening
  Serial.println(F("Armed"));
  digitalWrite(LED, HIGH);  //Turn the armed led on
  ledState = HIGH;   // arm the alarm
       lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print(F("Alarm On"));
  lcd.setCursor(0,1);
  lcd.print(F("Armed"));
}
void digitalClockDisplay() {
  // digital clock display of the time on serial port
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
}
void printDigits(int digits) {
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
  ///RTC section end
Improved code including SD cardArduino
I had a request to share my code for this project with the SD card included. Note the code has had a rewrite to save space. SD card is wired CS to pin 10, MOSI to 11, MISO to 12, SCK to 13. I never intended to share this code so it may not be commented correctly. The decimals included for the various sensors are fictional.
//Written by fourblackmans 14/2/2020
//Uno uses 46mA with lcd off 65 ma with LCD on 

#include <RCSwitch.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>  
#include <SPI.h>
#include <SD.h>


RCSwitch mySwitch = RCSwitch();// RCswitch recieves signals from  the 433Mhz senders   
LiquidCrystal_I2C lcd(0x27, 16, 2);  // set the LCD address to 0x27 0x3f for most 16 chars and 2 line displa

const int ALARM = 7;  // LED on pin 7 to indicate sender triggered while alarm armed
const int LED = 8; //Alarm armed LED
const int ALARM2 = 9;   /// pin 9 can have soloniod connected to action siren if sender triggered while alarm armed
const int chipSelect = 10; //sd CS pin
int ledState = LOW;  //Start in Disarmed state
int alarmState = LOW; // Start with alarm state as alarm not triggered

unsigned long previousMillis = 0; //for millis delay for length of time alarm sounds
const long interval = 120000; //for millis delay for length of time alarm sounds

unsigned long previousMillis2 = 0;// for millis delay time serial print
const long interval2 = 1000;         // for millis delay time serial print

const byte speakerPin=5;  // For beeper
unsigned long lastPeriodStart;// For beeper
const int onDuration=500;// For beeper
const int periodDuration=700;// For beeper



const char almloc1[] PROGMEM = "Office Cupboard";   // strings to store sensor location names - change to suit.
const char almloc2[] PROGMEM = "Office Window "; 
const char almloc3[] PROGMEM = "Bedroom Sliding"; 
const char almloc4[] PROGMEM = "Bedroom oth door"; 
const char almloc5[] PROGMEM = "Front Veranda"; 
const char almloc6[] PROGMEM = "Front Veranda 2"; 
const char almloc7[] PROGMEM = "Front Door"; 
const char almloc8[] PROGMEM = "Downstairs Veran"; 
const char almloc9[] PROGMEM = "Kai's window"; 
const char almloc10[] PROGMEM = "Back Veranda"; 
const char almloc11[] PROGMEM = "Laundry Door"; 
const char almloc12[] PROGMEM = "Kirra's Door"; 
const char almloc13[] PROGMEM = "Lounge Window"; 
const char almloc14[] PROGMEM = "Kitchen Window"; 
const char almloc15[] PROGMEM = "Lounge Door"; 
const char almloc16[] PROGMEM = "Garage"; 
const char almloc17[] PROGMEM = "Dining Door"; 
const char almloc18[] PROGMEM = "Dining Door 2"; 
const char almloc19[] PROGMEM = "External Bins"; 
const char almloc20[] PROGMEM = "External Pool"; 
const char almloc21[] PROGMEM = "Beer Room"; 
const char almloc22[] PROGMEM = "Garage Doors"; 
const char almloc23[] PROGMEM = "Garage 2"; 
const char almloc24[] PROGMEM = "Spare"; 
const char almloc25[] PROGMEM = "Spare"; 
const char almloc26[] PROGMEM = "Spare"; 

const char* const string_table[] PROGMEM = {almloc1,almloc2,almloc3,almloc4,almloc5,           //String table for PROGMEM
almloc6,almloc7,almloc8,almloc9,almloc10,almloc11,almloc12,almloc13,
almloc14,almloc15,almloc16,almloc17,almloc18,almloc19,almloc20,almloc21,almloc22,
almloc23,almloc24,almloc25,};

char buffer[30];    // make sure this is large enough for the largest string it must hold



void setup(){
  
  mySwitch.enableReceive(0);  //Myswitch waiting for 433mhz signals from senders on pin 2
  pinMode(8, OUTPUT);// Alarm Armed indicator led
  pinMode(13, OUTPUT); //turn led pin 13 off 
  pinMode(7, OUTPUT);  // Alarm triggered LED
  pinMode(9, OUTPUT); //Alarm triggered soloniod
  digitalWrite(LED, LOW);  //Start with armed LED off
  digitalWrite(ALARM, LOW);  //start with alarm LED off
 
  lcd.init();                      // initialize the lcd 
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print(F("Alarm ON"));
  lcd.setCursor(0,1);
  lcd.print(F("Disarmed"));
   
  //RTC section
  Serial.begin(9600);
   while (!Serial) ; 
  // get and set the time from the RTC
  setSyncProvider(RTC.get);   //get the time from RTC
  if (timeStatus() != timeSet) 
     Serial.println(F("Unable to sync with the RTC"));
  else
     Serial.println(F("RTC has set the system time"));     
   // to test your project, you can set the time manually 
   // setTime(22,14,55,1,1,11); // set time to 22:14 and 55 seconds on 1 Jan 2011

  // create  arm and disarm events  at specific times
  Alarm.alarmRepeat(6,00,0,MorningAlarm);  // DISARM time
  Alarm.alarmRepeat(22,15,0,EveningAlarm);  // ARM time
  //SD  card section start
  Serial.print(F("Initializing SD card..."));
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    lcd.setCursor(0,1);
    lcd.print(F("SD card failed"));
    }
   else {Serial.println(F("card initialized."));
   lcd.setCursor(0,1);
   lcd.print(F("SD Initialised  "));}
   
   // SD card section end   
}


void loop(){

  //RTC section
  {

  Alarm.delay(1); //Must be present TimeAlrams to work
}

   unsigned long currentMillis2 = millis();    //This section delays print time to serial to only once per second

  if (currentMillis2 - previousMillis2 >= interval2) {
    digitalClockDisplay();
    previousMillis2 = currentMillis2;
     }

  
  if (alarmState == LOW)          //This section sounds buzzer without using delay command
  { lastPeriodStart = millis();}    
  if(alarmState == HIGH) //if sender is triggered the alarm state is set high and sounds the buzzer while alarm remains high (this is ser for 120000 millis)
  {if (millis()-lastPeriodStart>=periodDuration)
  {lastPeriodStart+=periodDuration;
    tone(speakerPin, 1000, onDuration); // play 1000 Hz tone in background for 'onDuration'
 }
  }

 if(alarmState == HIGH) {digitalWrite(ALARM2, HIGH);} //If alarm triggered make alrm solonoid pin (9) high

 if(alarmState == LOW) {digitalWrite(ALARM2, LOW);}   //If alarm not triggered make alarm solonoid pin (9)low


 if (mySwitch.getReceivedValue() == 115161236 || mySwitch.getReceivedValue() ==9990592 || mySwitch.getReceivedValue() ==2917312) //Fob arm button code
    {ledState = HIGH;                  //if code is received set alarm state to armed
      digitalWrite(LED, HIGH);         // Turn on the alarm armed led
      tone(speakerPin, 1500);delay(100);noTone(speakerPin);delay(50); //Beep when Arming
      tone(speakerPin, 1500);delay(100);noTone(speakerPin);delay(50); 
      Serial.println(F("ON"));
      lcd.clear();
      lcd.setCursor(0,0); //Start at character 0 on line 0
      lcd.print(F("Alarm On"));
      lcd.setCursor(0,1);
      lcd.print(F("Armed")); }
    
 if (mySwitch.getReceivedValue() == 115781634 || mySwitch.getReceivedValue() == 9990412 || mySwitch.getReceivedValue() == 2917132)  //Fob disarm button code
 
  { ledState = LOW;   //if code is received set alarm state to disarmed
      digitalWrite(LED, LOW);     //Turn off the alarm led
      Serial.println(F("OFF"));
      digitalWrite(ALARM, LOW);
      alarmState= LOW;
      tone(speakerPin,1500);delay(100);noTone(speakerPin);delay(50); //beep when disarming
      lcd.clear();
      lcd.setCursor(0,0); //Start at character 0 on line 0
      lcd.print(F("Alarm On"));
      lcd.setCursor(0,1);
      lcd.print(F("Disarmed")); }
 
 
    
 if(ledState == HIGH && mySwitch.getReceivedValue() == 355175662) //Action for signal sender office cupboard
  { 
    strcpy_P(buffer, (char*)(string_table[0])); // Office cupbaord
    AlarmInfo();
  } 

  //LOW BAT
  if(mySwitch.getReceivedValue() == 355145488)
    {lcd.print(F("Office cupbrd LB")); }//Low battery warning
  
  if(ledState == HIGH && mySwitch.getReceivedValue() == 427225558) //Action for sender Office window
  {  
   strcpy_P(buffer, (char*)(string_table[1]));   //Office Window
    AlarmInfo();
    } 

    //LOW BAT
    if(mySwitch.getReceivedValue() == 427234286)
    {lcd.print(F("Office window LB")); }//Low battery warning

  if(ledState == HIGH && mySwitch.getReceivedValue() == 1066655646) //Action for sender Bedroom door
  {  
    strcpy_P(buffer, (char*)(string_table[2])); //Bedroom Sliding
    AlarmInfo();
      } 

    //LOW BAT
     if(mySwitch.getReceivedValue() == 1064565472)
    { lcd.print(F("Bed Slide LB   "));}//Low battery warning

    
    
    if(ledState == HIGH && mySwitch.getReceivedValue() == 1665357806) //Action for sender Other bedroom door
  {  
  strcpy_P(buffer, (char*)(string_table[3])); //Bedroom other
    AlarmInfo();
  
   } 


  
if(mySwitch.getReceivedValue() == 16357632)
{lcd.print(F("Bed oth door LB "));}//Low battery warning
  
    
    if(ledState == HIGH && mySwitch.getReceivedValue() == 295236636) //Action for sender Front veranda
  {  
   strcpy_P(buffer, (char*)(string_table[4]));  //"Front veranda 
    AlarmInfo();
     } 

        if(ledState == HIGH && mySwitch.getReceivedValue() == 401444428) //Action for sender Front veranda 2
  {  
   strcpy_P(buffer, (char*)(string_table[5])); // "Front veranda 2"
    AlarmInfo();
    } 
        
    if(ledState == HIGH && mySwitch.getReceivedValue() == 83512246) //Action for sender Front door
  {  
    strcpy_P(buffer, (char*)(string_table[6])); //  "Front Door "
    AlarmInfo();
  
   }

// LOW BAT

if (mySwitch.getReceivedValue() == 83503572)

{  lcd.print(F("Front door LB")); }  //Low battery warning


     
    if(ledState == HIGH && mySwitch.getReceivedValue() == 317986865) //Action for sender Down stairs veranda
  {  
   strcpy_P(buffer, (char*)(string_table[7])); //"Downstairs veran"
    AlarmInfo();
   
    } 
    
    if(ledState == HIGH && mySwitch.getReceivedValue() == 744495610) //Action for sender Kais window
  {  
  strcpy_P(buffer, (char*)(string_table[8])); // "Kai's Window "
    AlarmInfo();
    
      } 

// LOW BAT      
if(mySwitch.getReceivedValue() == 7444736)
 { lcd.print(F("Kai Win LB    ")); }    
      
    if(ledState == HIGH && mySwitch.getReceivedValue() == 328841512) //Action for Back Veranda
  {  
   strcpy_P(buffer, (char*)(string_table[9])); // "Back veranda"
    AlarmInfo();
  
     } 
     
    if(ledState == HIGH && mySwitch.getReceivedValue() == 1312851528)//Action for sender Laundry door
  {  
 strcpy_P(buffer, (char*)(string_table[10])); // "Laundry Door "
    AlarmInfo();
  
   } 
   
    if(ledState == HIGH && mySwitch.getReceivedValue() == 1580625894) //Action for sender Kirras door
  {  
   strcpy_P(buffer, (char*)(string_table[11])); // "Kirra's Door "
    AlarmInfo();
  
      } 

 // LOW BAT
 if(mySwitch.getReceivedValue() == 15806720)
 { lcd.print(F("Kir door LB"));   }   
      
    if(ledState == HIGH && mySwitch.getReceivedValue() == 1324586224) //Action for sender Lounge window
  {  
   strcpy_P(buffer, (char*)(string_table[12])); // "Lounge window "
    AlarmInfo();
    
    } 
    
    if(ledState == HIGH && mySwitch.getReceivedValue() == 1087254400) //Action for sender Kitchen window
  {  
   strcpy_P(buffer, (char*)(string_table[13])); // "Kitchen Window"
    AlarmInfo();
  
    } 
    
    if(ledState == HIGH && mySwitch.getReceivedValue() == 1669845448) //Action for sender lounge doors
  {  
  strcpy_P(buffer, (char*)(string_table[14])); // "Lounge Door"    tamper code = trigger -74
    AlarmInfo();
   
    } 
    
    if(ledState == HIGH && mySwitch.getReceivedValue() == 159816574916) //Action for sender Garage
  {  
  strcpy_P(buffer, (char*)(string_table[15])); // "Garage"
    AlarmInfo();
   
    } 
    
    if(ledState == HIGH && mySwitch.getReceivedValue() == 1388147524) //Action for sender Dining doors
  {  
   strcpy_P(buffer, (char*)(string_table[16])); // "Dining Door" hasno tamper switch
   AlarmInfo();
   
   }
    if(mySwitch.getReceivedValue() == 1388145353) { lcd.print(F("Dining door  LB "));   }  // LB code LB code for wolfguard reeds= trigger code -71 
   

    if(ledState == HIGH && mySwitch.getReceivedValue() == 1629445992) //Action for sender Dinings doors 2
  {  
   strcpy_P(buffer, (char*)(string_table[17])); // "Dining door 2" tamper code 16294918  tamper code = trigger -74
    AlarmInfo();
   
    } 
    if(mySwitch.getReceivedValue() == 1629425921) { lcd.print(F("Dining door 2 LB"));   }  // LB code LB = trigger code possible -80 for older sender with no tamper
    
    
    if(ledState == HIGH && mySwitch.getReceivedValue() == 1159323657) //Action for sender External Bins
  {  
   strcpy_P(buffer, (char*)(string_table[18])); // "External Bins"
    AlarmInfo();
  
    } 

    if(ledState == HIGH && mySwitch.getReceivedValue() == 1544451321) //Action for sender External Pool
  {  
   strcpy_P(buffer, (char*)(string_table[19])); // "External Pool"
    AlarmInfo();
  
       } 

    if(ledState == HIGH && mySwitch.getReceivedValue() == 832896540) //Action for sender Beer Room
  {  
   strcpy_P(buffer, (char*)(string_table[20])); // "Beer Room"
    AlarmInfo();
   
    } 

    
    if(ledState == HIGH && mySwitch.getReceivedValue() == 428865860) //Action for sender Garage Doors
  {  
   strcpy_P(buffer, (char*)(string_table[21])); // "Garage Doors"
    AlarmInfo();
  
    } 

    if(ledState == HIGH && mySwitch.getReceivedValue() == 83525092) //Action for sender Garage 2
  {  
   strcpy_P(buffer, (char*)(string_table[22])); //"Garage 2"
    AlarmInfo();
    
  } 

unsigned long currentMillis = millis();   //This section allows the alarm state and alarm led to remain on for a set period

  if (currentMillis - previousMillis >= interval) {
     previousMillis = currentMillis;
    // if the alarm state and alarm led is on turn it off:
         alarmState = LOW;
      digitalWrite(ALARM, LOW);
   }
     
   

  mySwitch.resetAvailable(); 
     Alarm.delay(50);//for stability
     
}
///Section for functions

// functions to be called at certain times of day

// Disarm the alarm in the moring from RTC
void MorningAlarm() {
  // write here the task to perform every morning
  Serial.println(F("Disarmed"));
  digitalWrite(LED, LOW);  //turn the armed led off
  ledState = LOW;//  disarm the alarm
       lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print(F("Alarm On"));
  lcd.setCursor(0,1);
  lcd.print(F("Disarmed"));
}
//Arm the alarm at night from RTC
void EveningAlarm() {
  // write here the task to perform every evening
  Serial.println(F("Armed"));
  digitalWrite(LED, HIGH);  //Turn the armed led on
  ledState = HIGH;   // arm the alrm
       lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print(F("Alarm On"));
  lcd.setCursor(0,1);
  lcd.print(F("Armed"));
}
//RTC Finctions
void digitalClockDisplay() {
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
}
void printDigits(int digits) {
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
  ///RTC section end
  
// start function action when sensor triggered (alarm data to LCD and SD)
void AlarmInfo()
{   //LCD Start 
    previousMillis = millis();   
    digitalWrite(ALARM, HIGH);    //turn on the alarm LED
    alarmState = HIGH;  //Set the alarm state to alarm going off
    
  lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print(F("Alarm"));   //print message to lcd to know which sensor is was activated (and go and find the burglar :)
  lcd.setCursor(7, 0);  // PRINT hour to LCD
  if (hour() < 10)             
  lcd.print(F("0"));
  lcd.print(hour());
  lcd.setCursor(9, 0);// PRINT : to lcd
  lcd.print(F(":"));
  lcd.setCursor(10, 0);// PRINT minutes to LCD
  if (minute  () < 10)
  lcd.print(F("0"));
  lcd.print(minute());
  lcd.setCursor(0,1);
  lcd.print(buffer);  //Name alarm senson that was triggered
  //LCD end
  
 //SD start    
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  dataFile.print(buffer);
  dataFile.print(F(","));dataFile.print(hour());dataFile.print(F(":"));
  if (minute() < 10)
  dataFile.print(F("0"));
  dataFile.print(minute());
  dataFile.print(F(" "));
  dataFile.print(day());dataFile.print(F("/"));dataFile.print(month());dataFile.print(F("/"));
  dataFile.print(year()); dataFile.println();dataFile.close();
  //SD end 
  } 
// Alarm data function 
//end function section
Github
https://github.com/sui77/rc-switch/wiki

Schematics

Fritzing
Frizting gxjiogqas2

Comments

Similar projects you might like

Entry Level Door Monitoring Alarm System

Project tutorial by Team Robodia Technology Solutions

  • 7,156 views
  • 1 comment
  • 18 respects

Buzzer Alarm System With Help Of Arduino

by Team ONYX

  • 62,119 views
  • 10 comments
  • 38 respects

Alarm System Security Put to the Test

Project tutorial by danionescu

  • 15,848 views
  • 5 comments
  • 26 respects

Plant watering alarm system with arduino

Project tutorial by Giannis Arvanitakis

  • 7,500 views
  • 2 comments
  • 12 respects

DIY Arduino Fire Alarm System At Home

Project tutorial by MrModder

  • 22,066 views
  • 1 comment
  • 25 respects

DIY Temperature & Humidity & Smoke Detector Alarm System

Project tutorial by ICStation Team

  • 12,343 views
  • 0 comments
  • 13 respects
Add projectSign up / Login