Home    Master Clock   LCD Master Clock    Kenley Weather

Section   Top   About  Features   PushingBox    Pushbullet  Power up Fail Alert  Power up Alert Smoke Alarm Alert   Burglar Alarm Alert   Doorbell Alert  Schematic   Schematic 2   Wiznet 2009 Mod  Code

 

 

 

Arduino Push Alerts

IoT Notifications for your Doorbell, Burglar Alarm, Smoke Alarms etc

Using an Arduino Uno and an Ethernet Shield

Control Box

 

Arduino Uno with Ethernet Shield R3 Attached

 

About Arduino Push Alert Box

Uses an Arduino Uno and Ethernet card to send push alerts on smoke alarm, burglar alarm and doorbell activations via PushingBox.

 

All alerts ignore situations/wiring faults that give rapid multiple triggers. This prevents massive amounts of false alert messages being sent to you mobile phone.

 

The alerts can also be tied into any web cams installed in your house/office. This is done via the PushingBox interface.

 

The PushingBox services list includes all types of phone (Android,Windows and Iphone), computer (Mac, Windows PC and Chromebook) and also includes mail and twitter.

 

If you use Pushbullet, alerts are also repeated on your PC/Chromebook and very soon Mac OS.



 

Burglar Alarm

Sends alerts when the sounder is activated and also when the sounder is turned off through timeout or user intervention. Connects via the aux sounder output on my main alarm panel.


 

Smoke Alarm

Uses a modified smoke alarm in a wireless networked smoke alarm system as an interface. Senses when the smoke alarms sound for a real alert and ignores low battery/fault alerts. It does this by measuring the delay between sounder chirps.

Connects via an optocoupler on the modified smoke alarm sounder output.


 

Doorbell Alert

When your doorbell is pressed your conventional doorbell rings as normal but an alert is also send to all your devices. It also has an interface to page all phones on a wireless phone system when the doorbell rings.

Most of the circuitry is used for the telephone pager interface that was part of an existing project. This circuitry can easily be omitted and replaced see minimal schematic diagram.

The doorbell code will need to be adjusted to take these into account. This will make for a much simpler project.


 

 

 

 

Features

Instant push alerts for Doorbell, Burglar Alarm Sounder Activating, Burglar Alarm Sounder Deactivating, Smoke Alarm and Ethernet power restore.

Any number of alert types can be sent to multiple locations, mobiles, tablets, laptops, desktops and chrome books.

Multiple false alerts are ignored eg multiple doorbell pushes will only create 1 alert and faulty sensor wiring will only create 1 alert.

Using the doorbell interface your standard doorbell will also ring as normal and if switched on all your wireless house phone will ring using their built in paging function.

Uses around 2Watts of power.

Auto reset and alert on power restore after a power cut

 

PushingBox

Alerts are sensed by the Arduino mounted in the Push Alert Box and are sent via the Ethernet card to PushingBox.

PushingBox then pushes the alerts out to your Services and are then pushed on to all your devices.

                 

 

 

I have included examples of the following alerts in my code: Doorbell, Burglar Alarm Sounder Activating, Burglar Alarm Sounder Deactivating, Smoke Alarm and Ethernet power restore.

Alerts could easily be setup for freezer alarms, greenhouse alarms, tropical fish tank temperature alarms and any number of other alarms.

 

 

             

               PushingBox demo video

 

 

The alerts are sent via the Ethernet card to PushingBox where you setup various "Scenarios" for each of your alerts. Each "Scenario" contains "Services" that are custom setup for your alerts.

 

The PushingBox Services page showing the the various Services that are available for your Scenarios.

You can add as many Services as you wish e.g. if your Burglar Alarm goes off you may want to send an instant alert via Pushbullet to all your devices and also an email alert with a picture from your web cam.

If you go to PushingBox API tab you can find examples of code for Arduino Ethernet Shields. I have written this code based on the "Official Ethernet Shield Wiznet" code downloaded from the site.

I have used the R3 Ethernet board as it has a built in reset chip but the older board can be used with a simple hardware modification.

 

Pushbullet

As well as a service on PushinBox I use Pushbullet to forward all my mobile alerts to my Windows PC and Chromebook. Whenever alerts appear on my mobile they also pop up on my PC/Chromebook.

If I dismiss them on my PC/Chromebook they are also dismissed on my mobile this also includes the alert LED on the front of my Mobile. Pushbullet now works with Whatsapp so I can answer my Whatsapp

message and conversation via my Windows PC.

 

 

 

Alerts

 

Power Up Fail Alert

On power being restored or on initial power up the Ethernet card will try to connect to the internet. On R3 boards there is a reset chip that resets the card on power up and should ensure the card connects without fail.

On cards below R3 the card tends not to reconnect on power up. There is a mod you can carry out that gives the card a reset when it is powered up and gives good results.

In case your card fails to reconnect after loss of power (you will not get any alerts) I have set the Arduino to light a flashing LED as a warning. The LED will flash as the card reconnects then should go out.

 

 

 

Power Up Alert

On power being restored to the Push Alert Box an alert is sent out once the Ethernet card has successfully reconnect to the internet. This will warn you that there has been a power failure at some time and warns you to

check all the systems are working again when you get back home.

The IoT interface box has test switches to allow you to test all the systems are alerting. The smoke alarms can be tested by pressing any smoke alarm "test  button".

           

             Real-time Video of my IoT interface box in it's design stage on first power up.

             A section of my PC screen is on the right showing received alerts while my mobile phone is on the left of the screen.

             I use the Newtifry spoken alerts on my mobile wh en system testing so I can hear what alerts are being sent out.

 

 

                        

             Power up alert demo from my desktop showing desktop alerts, Arduino com port output

             and my mobile alerts superimposed over the top.

 

 

 

Smoke Alarm Alert

I use Wireless Networked Smoke Alarms so any smoke alarm sounding will trigger all other smoke alarms in the same network.

To connect to my IoT interface box I purchased an extra box to use as a "Master" alarm.

Smoke Alarms are a safety device and as the "Master" alarm has to be hacked I did not want to hack an alarm in a live location.

This means if my hack fails and causes a malfunction in the "Master" alarm all other alarms will keep working.

 

                            

                                                    Smoke optical isolator alarm interface. Link set to 5v.

 

I have used a optical isolator to get the alarm signal off the "Master" smoke alarm. I tried to connect off the alarm LED but I could not get it to trigger the optical isolator so instead I connected the

optical isolator off the sounder.

       

                Vero layout for Doorbell Relay Optical isolator and spare pull up/down resistors

   

 

          

            Demo video showing test smoke alarm alerts received on my desktop PC along with

            the Arduino com port output and mobile phone alerts superimposed on top

 

 

There are other networked smoke alarms out there that include a master smoke alarm in the range and have relay outputs. This would make for a much simpler interface but the drawback is

they are wired and also cost 2 to 3 times the price.

 

                              

 

As I have connected off the smoke alarm sounder output the modified "master" alarm will not sound but will still trigger and be triggered by the other smoke alarms. My "master" alarm is an additional alarm so this will not compromise the safety

of my house. The Arduino is used to detect the alarm "chirps" and decide if the an alert needs to be sent. In a real smoke alarm situation the smoke alarms chirp 3 times at half second intervals with a 1.5 second gap.

When the Arduino sees this pattern it send out an alert.

 

If the smoke alarm sensor wiring was to fail a continuous output would be sent. The Arduino is sent to ignore any inputs of less than 300m seconds. Likewise when a battery on any smoke alarm fails or there is a system error

the alarms will sound 1 chirp every 48 seconds to warn you. The Arduino will always wait after receiving the first "chirp" and time how quick another "chirp" is received. If time between "chirps" is too long then the "chirp" is ignored

and an alert is not sent. You could if you wish send out an alert to let yourself know that a battery need changing or the system has an error.

The Arduino code will of course need to be modified to suit different types of smoke alarms.

 

Burlgar Alarm Sounder Activation/Deactivation Alert

When the Burglar Alarm Sounder is activated the aux sounder output is used to trigger a relay in the control box. This relay triggers the Burglar Alarm Sounder alert.

 

      

              12v relay operated from the alarm panel aux sounder output

 

 

           

            Video showing Push alerts on my desktop and also on my mobile superimposed over the top

 

When the sounder is turned off or is reset the state is detected and an alert is sent to inform you that the sounder is off.

If a wiring fault develops on the sensor wire and it becomes disconnected multiple alerts would be sent so the Arduino is set to detect and ignore rapid alerts.

If you want to hack into your burglar alarm panel you should be able get outputs off the LED alert indicators so you can make custom alerts depending on which zones have been activated eg. panic, internal or external doors.

 

              

 

 

Doorbell

The doorbell alert is based on my existing doorbell and telephone interface with a few mods. The hard wired interface can be left out if not required and the doorbell code could be modified to take it's place. I have used it as it exists already

from a previous project and there was space on the Vero board for some of the additional components for the other alerts. See the schematic with minimal components for details.

In my setup the doorbell push operates the standard wireless doorbell via a relay, sends an alert via PushingBox to all my devices and if the "Phone Paging" switch is operated will ring all my wireless telephones in the house, garage outbuildings etc.

If you have a web cam on the front door an image can be included in the alert.

 

            

 

 

 

 

 

           

                                                 Video showing Doorbell Push alerts on my mobile/desktop and home phone system.

 

 

Doorbell Circuit Overview

When the doorbell push is operated a relay operates in the control box. This relay operates the standard doorbell in my case a modified wireless doorbell and also starts a 555 timer on the doorbell interface.

The 555 timer operates another relay to trigger the paging circuit on my wireless phones. If the "phone/paging" switch is on all the wireless phones in the house will be paged until they time out (1 minute on my phones).

The 555 timer prevents repeated doorbell pushes resetting the telephone pager and turning the pager off and also stops extra alerts being sent out for the same visitor.

Any room in the house, garage, workshop or office with a wireless phone in will get notification that the doorbell has been pressed. The doorbell push is also illuminated by a flashing LED to show the caller that the doorbell is continuously ringing.

A doorbell alert is also sent out to all your mobile & fixed devices.

 

         

          Typical Alert. Pushbullet grabs a picture and instantly pushes

          a notification out controlled by Pushingbox.

 

Once the telephone pagers have timed out the doorbell push will stop flashing.

A further push on the doorbell will then send out another alert and start the telephone pagers again.

Once you get to the front door a doorbell reset switch is pushed and this will instantly stop the telephone pagers from ringing and reset the doorbell. You can set an alert to inform you that the door has been answered.

This is handy if you are away and you are expecting an important package you will get an alert for the doorbell being operated then an alert to show someone else has answered the door.

 

The main doorbell push switch is modified by adding a flashing LED.

Standard Bell Push Front Standard Bell Push Back Modified Bell Push with wiring for a Flashing LED Modified Bell Push Showing Bell Ringing

 

 

 

General Schematic

Complete schematic showing doorbell interface board and relays for Smoke and Burglar alarms.

Most of the circuitry is used for the doorbell interface and can be left out and replaced by code if required.

See the schematic with minimal components for details.

Doorbell/ Telephone paging Circuit Detail

In it's normal state the "bell push" switch and  "bell silence" switches are open and the relay is not operated.

IC1a and IC1b are both wired as monostables.

On pressing the "bell push" switch the trigger of IC1a is taken low by relay RL3 ctk 3&4 making. RL3 ctk 6&7 making operate the traditional doorbell. The output of IC1a therefore goes high switching on transistor Q1. This causes LED D6 (flashing LED) to light and sends a pulse through capacitor C2.

This pulse takes the trigger of IC1b low and therefore the output of IC1b goes high operating relay RL1. Relay RL1 operating shorts the telephone base "find handset" or "paging" terminals causing all the phones on that base to ring.

IC1a monostable time period is set by C1,VR1 and R6. VR1 is adjusted so that the monostable time period is a few seconds longer than the phones ring for eg 30secs for a Diverse 6410 or 60sec for a Diverse 7410. This ensures that multiple pressing of the "bell push" switch do not retrigger IC1a and b causing the bells to stop ringing.

IC1b monostable time period is set by C3,VR2 and R7. VR2 is adjusted to give a short period (usually less than a second) just enough to trigger the telephone base.

The "bell silence" switch when pressed resets IC1a by taking it's reset pin low. IC1a output then goes low stopping the LED from lighting. IC1b trigger is also taken low so the output then goes high for the set period of the monostable operating RL1 and stopping the phones from ringing. Note if the "bell silence" switch is held down the monostable time period of IC1b is overridden and RL1 remains operated while the "bell silence" switch is held down. This can be used to set up the phones to the base station as they often require the "find handset" or "paging" button held down for a number of seconds to activate a handset search.

Note the optional "ring repeater" LED can be used to give a visual indication that the doorbell is ringing in a noisy room.

 

 

             

                                                                                                                       Main doorbell layout

Wiring

You will need to take a 6 wire cable to the door or use 3 x 1pr bell wire. 1pr connects to the normal door bell push switch, 1pr to the flashing LED and 1pr to the bell silence switch. Note I just used another standard door bell push for the bell silence switch. I mounted it on the door frame on the opposite side to the bell push. Mount the "bell ringing" LED in the door bell push in a suitable holder and label if required.

If the optional ring repeater LED is required then 1 pr cable is required as well.

You will need to run a 1pr cable to you telephone base. This will need to be connected across the "find handset" or "paging" terminals on the PCB of your base.

 

 Warning.

Note this involves taking your base apart and soldering directly to the PCB. Every phone is different and some may not even have a paging function or if they do the switch may not be accessable.  This of course will invalidate your warrantee and may also destroy your phone. Only carry this out if you are competent to do so and always disconnect the power and phone line connection to the base first. If you cause a fault on your phone or line your service provider may well charge you to sort it out.

 

 

Schematic with minimal components

You can do away with most of the components above and just use the Arduino to control the doorbell and telephone paging.

The circuit can be simplified further if telephone paging from the doorbell is not required, just omit the 2 sections indicated below. The ring indicator can also be omitted as this just indicates the paging timeout period.

           

 

 

 

 

 

 

 Wiznet  2009 Ethernet reset Mod

Wiznet R3 boards come with a reset chip that resets the Ethernet board on power up. If you board is not R3 you could try this mod.

You will need bend the reset pin away so it does not make contact with the reset socket on the Arduino Uno.

Solder a 10k resistor and 100nF capacitor to this pin.

Solder the other end of the resistor to the 3v3 pin and the other end of the capacitor to the Gnd pin.

 

         

                                 Reset modification to 2009 Ethernet boards. Mouse over to zoom in.

 

 

Arduino Code

The code below is for the circuit with the hard wired telephone paging.

Added 4min delay on first power up to give your router/hub time to reconnect

If you are using the schematic with minimal components just modify the Doorbell part of the code.

 

////
//
// General code from http://www.pushingbox.com for Arduino + Ethernet Shield (official) v1.2
//
//  pushingbox alarts
//  http://www.brettoliver.org.uk
//
//  Copyright 2015 Brett Oliver
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program. If not, see http://www.gnu.org/licenses/
//
////

#include <SPI.h>
#include <Ethernet.h>

/////////////////
// MODIFY HERE //
/////////////////
byte mac[] = { 0x, 0x, 0x, 0x, 0x, 0x };   // Be sure this address is unique in your network

//Your secret DevID from PushingBox.com. You can use multiple DevID  on multiple Pin if you want
char DEVID1[] = "enter device id from PushingBox";        //Scenario : "Doorbell"
char DEVID2[] = "enter device id from PushingBox";        //Scenario : "Burglar Alarm Sounding"
char DEVID3[] = "enter device id from PushingBox";        //Scenario : "Power restored"

char DEVID5[] = "enter device id from PushingBox";        //Scenario : "Bell Silence pressed"
char DEVID6[] = "enter device id from PushingBox";        //Scenario : "Burglar Alarm Sounder off"
char DEVID7[] = "enter device id from PushingBox";        //Scenario : "Smoke Alarm Sounder On"
//char DEVID8[] = "enter device id from PushingBox";        //Scenario : "Smoke Alarm Sounder off"
//char DEVID9[] = "enter device id from PushingBox";        //Scenario : "Smoke Alarm Maintenance"




//Numeric Pin where you connect your switch
uint8_t pinDevid1 = 3; // the doorbell switch is connected to Pin 3, also relay from telephone pager to prevent doorbell push sending another alert
uint8_t pinDevid2 = 5; // the burglar alarm switch is connected to Pin 5
uint8_t pinDevid7 = 7; // the smoke alarm sensor is connected to Pin 7
int bellState = 2; // the bell ringing sensor wire is connected to Pin 2
//int smokeinterval = 0; // diff between smoke on and smoke off interval

int pwrRestoreLED = 6; // when power restored or on 1st power up this LED is lit until succesful power up is transmitted
long prevDEVID5Millis = 0;        // will store last time DEVID5 was sent
long DEVID5interval = 0; // this is the interval between sending DEVID5
long prevDEVID1Millis = 0;        // will store last time DEVID1 was sent
long DEVID1interval = 0; // this is the interval between sending DEVID1
long prevDEVID2Millis = 0;        // will store last time DEVID2 was sent
long DEVID2interval = 0; // this is the interval between sending DEVID2
long prevDEVID6Millis = 0;        // will store last time DEVID6 was sent
long DEVID6interval = 0; // this is the interval between sending DEVID6
long prevDEVID7Millis = 0;        // will store last time DEVID7 was sent
long DEVID7interval = 0; // this is the interval between sending DEVID7
//long prevDEVID8Millis = 0;        // will store last time DEVID7 was sent
//long DEVID8interval = 0; // this is the interval between sending DEVID7

int bellsilencepwr = false; // allows interval time is ignored on 1st power up
int doorbellpwr = false; // allows interval time is ignored on 1st power up
int burglarpwr = false; // allows interval time is ignored on 1st power up
int sounderOffpwr = false; // allows interval time is ignored on 1st power up
int burglarActvated = false; // sets condition for sensing buglar alarm sound deactivating
int smokepwr = false; // allows interval time is ignored on 1st power up
int smokeActvated = false; // sets condition for sensing smoke alarm sound deactivating
int smokeOffpwr = false; // allows interval time is ignored on 1st power up

// Debug mode
boolean DEBUG = true;
//////////////
//   End    //
//////////////


char serverName[] = "api.pushingbox.com";
boolean pinDevid1State = false;                // Save the last state of the Pin for DEVID1
boolean pinDevid2State = false;                // Save the last state of the Pin for DEVID2
boolean pinDevid6State = false;                // Save the last state of the Pin for DEVID6
boolean pinDevid7State = false;                // Save the last state of the Pin for DEVID7
//boolean pinDevid8State = false;                // Save the last state of the Pin for DEVID8
boolean Devid3State = false;                // Save the last state for DEVID3
boolean lastConnected = false;                 // State of the connection last time through the main loop
boolean smoke = false;                         // stops repeat reporting of smoke alarm until no chirp for >40 secs


// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  delay( 50 );   // allow some time (50 ms) after powerup and sketch start, for the Wiznet W5100 Reset IC to release and come out of reset.
  Serial.begin(9600);
  pinMode(pinDevid1, INPUT);
  pinMode(pinDevid2, INPUT);
  pinMode(pinDevid7, INPUT);
  pinMode(bellState, INPUT);
  pinMode(pwrRestoreLED, OUTPUT);
 
 // give your router/hub 4 mins to initialize on power restore
  digitalWrite(pwrRestoreLED, HIGH); // lights Power restored LED
  delay(240000);
  digitalWrite(pwrRestoreLED, LOW); // lights Power restored LED
  
  
  

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while (true);
  }
  else {
    Serial.println("Ethernet ready");
    // print the Ethernet board/shield's IP address:
    Serial.print("My IP address: ");
    Serial.println(Ethernet.localIP());
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);

  digitalWrite(pwrRestoreLED, HIGH); // lights Power restored LED until " sendToPushingBoxPower(DEVID3);" is sent
  //Sending request to PushingBox on 1st power up
  sendToPushingBoxPower(DEVID3);    //On power up runs Power restored scenario won't start loop until DEVID3 sucseeds
  digitalWrite(pwrRestoreLED, LOW); // Power restored LED is off and stays off until power is shut down and restored

}

void loop()
{
  ////
  // Listening for the pinDevid1 state (Doorbell Push)
  ////

  if (digitalRead(pinDevid1) == LOW && pinDevid1State == false) // switch on pinDevid1 is ON
  {
    if (DEBUG) {
      Serial.println("Doorbell Off");
    }
    pinDevid1State = true;

    //Serial.print ("Sending request to PushingBox when the pin is HIGH");
    // sendToPushingBox(DEVID1); //disabled
  }
  if (digitalRead(pinDevid1) == HIGH && pinDevid1State == true && digitalRead(bellState) == HIGH) // switch on pinDevid1 is On and if DoorBell output is High
  {
    if (DEBUG) {
      Serial.println("Doorbell On");
    }
    pinDevid1State = false;
    unsigned long currentDEVID1Millis = millis(); // Millis value when "door bell" pressed
    DEVID1interval = currentDEVID1Millis - prevDEVID1Millis; // Time in mseconds between bell silence being pressed

    prevDEVID1Millis = currentDEVID1Millis; // resets Millis value to current value
    Serial.print("Doorbell interval ");
    Serial.println(DEVID1interval);

    if (DEVID1interval > 30000 || doorbellpwr == false) // If "door bell" is pressed again in less than 30000 mseconds then DEVID5 is not sent
      // (unless doorbellpwr is false initial power up only)
    {

      //Sending request to PushingBox when the bellState is High (Bell Silence not pressed) and pinDevid1 is High(doorbell pressed) and elapsed time is > 30000 mseconds
      sendToPushingBox(DEVID1);    // request sent to PushingBox
      doorbellpwr = true; // door bell press elapsed time is now enabled
    }
    else
    {
      Serial.println("Doorbell pushed <30sec");
    }
  }






  ////
  // Listening for the pinDevid1 state (Bell Silence pressed)
  ////

  if (digitalRead(pinDevid1) == LOW && pinDevid1State == false) // switch on pinDevid1 is ON
  {
    if (DEBUG) {
      Serial.println("Bell silence Off");
    }
    pinDevid1State = true;

    //Serial.print ("Sending request to PushingBox when the pin is HIGH");
    // sendToPushingBox(DEVID1); //disabled
  }
  if (digitalRead(pinDevid1) == HIGH && pinDevid1State == true && digitalRead(bellState) == LOW) // switch on pinDevid1 is On and if DoorBell output is LOW

  {
    if (DEBUG) {
      Serial.println("Bell silence On");
    }
    pinDevid1State = false;

    unsigned long currentDEVID5Millis = millis(); // Millis value when "bell silence" pressed
    DEVID5interval = currentDEVID5Millis - prevDEVID5Millis; // Time in mseconds between bell silence being pressed

    prevDEVID5Millis = currentDEVID5Millis; // resets Millis value to current value
    Serial.print("Bell Silence interval ");
    Serial.print(DEVID5interval);
    Serial.print(" Bell Silence Power ");
    Serial.println(bellsilencepwr);

    if (DEVID5interval > 30000 || bellsilencepwr == false ) // If "burglar alarm sounds" again in less than 30000 mseconds then DEVID2 is not sent
      // (unless bellsilencepwr is false initial power up only)
    {
      //Sending request to PushingBox when the bellState is LOW (Bell Silence pressed) and pinDevid1 is High(doorbell ringing) and elapsed time is > 30000 mseconds
      sendToPushingBox(DEVID5);    // request sent to PushingBox
      bellsilencepwr = true; // bell silence press elapsed time is now enabled
      //  digitalWrite(pwrRestoreLED, LOW); // Power restored LED is off and stays off until power is shut down and restored
    }
    else
    {
      Serial.println("DEVID5 trigger interval less than 30 seconds");
      // digitalWrite(pwrRestoreLED, LOW); // Power restored LED is off and stays off until power is shut down and restored
    }
  }





  // Listening for the pinDevid2 state (Burglar Alarm Sounding)
  ////
  if (digitalRead(pinDevid2) == LOW && pinDevid2State == false) // switch on pinDevid2 is ON
  {
    if (DEBUG) {
      Serial.println("BA Off");
    }
    pinDevid2State = true;


    //sendToPushingBox(DEVID2); //Deactivated
  }
  if (digitalRead(pinDevid2) == HIGH && pinDevid2State == true) // switch on pinDevid2 is OFF
  {
    if (DEBUG) {
      Serial.println("BA On");
    }
    pinDevid2State = false;

    unsigned long currentDEVID2Millis = millis(); // Millis value when "burglar alarm sounded" pressed
    DEVID2interval = currentDEVID2Millis - prevDEVID2Millis; // Time in mseconds between bell silence being pressed

    prevDEVID2Millis = currentDEVID2Millis; // resets Millis value to current value
    Serial.print("DEVID2 interval ");
    Serial.println(DEVID2interval);

    if (DEVID2interval > 30000 || burglarpwr == false) // If "burglar alarm " is sounding again in less than 30000 mseconds then DEVID2 is not sent
      // (unless burglarpwr is false initial power up only)
    {

      //Sending request to PushingBox when the bellState is High (Bell Silence not pressed) and pinDevid1 is High(doorbell pressed) and elapsed time is > 30000 mseconds
      sendToPushingBox(DEVID2);    // request sent to PushingBox
      burglarpwr = true; // burglar alarm sounding elapsed time is now enabled
      burglarActvated = true; // sets condition for sensing buglar alarm sound deactivating //*******************************************

      Serial.println("Burglar Alarm Sounder On");
    }
    else
    {
      Serial.println("Burglar Alarm trigger interval <30sec");

    }

  }


  // ***************************************************************
  // Listening for the pinDevid2 state (Burglar Alarm Sounder Deactivating) When burglar alarm sounder is turned off or times out DEVID6 is sent

  if (digitalRead(pinDevid2) == HIGH && pinDevid6State == false) // switch on pinDevid2 is ON
  {
    if (DEBUG) {
      Serial.println("Burglar Alm On");
    }
    pinDevid6State = true;


  }
  if (digitalRead(pinDevid2) == LOW && burglarActvated == true && pinDevid6State == true) // sets condition for sensing buglar alarm sound deactivating)
    // switch on pinDevid2 is OFF burglarActvated == true is set when alarm sounder is triggered in "DEVID2" above
  {
    if (DEBUG) {
      Serial.println("Burglar Alm Off");
    }
    pinDevid6State = false;

    unsigned long currentDEVID6Millis = millis(); // Millis value when "burglar alarm sounded" pressed
    DEVID6interval = currentDEVID6Millis - prevDEVID6Millis; // Time in mseconds between bell silence being pressed

    prevDEVID6Millis = currentDEVID6Millis; // resets Millis value to current value
    Serial.print("BA interval ");
    Serial.println(DEVID6interval);

    if (DEVID6interval > 30000 || sounderOffpwr == false) // If "burglar alarm " is sounding again in less than 30000 mseconds then DEVID2 is not sent
      // (unless burglarpwr is false initial power up only)
    {

      //Sending request to PushingBox when the bellState is High (Bell Silence not pressed) and pinDevid1 is High(doorbell pressed) and elapsed time is > 30000 mseconds
      sendToPushingBox(DEVID6);    // request sent to PushingBox
      sounderOffpwr = true; // burglar alarm sounding elapsed time is now enabled
      burglarActvated = false; // sets condition for sensing buglar alarm sound deactivating //*******************************************

      Serial.println("Burglar Alarm Sounder Off");
    }
    else
    {
      Serial.println("Burglar Alarm off interval <30secs");

    }

  }
  //*********************************************************





  // Start Smoke alarm ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  // Listening for the pinDevid7 state (Smoke Alarm Sounding)
  ////
  if (digitalRead(pinDevid7) == HIGH && pinDevid7State == false) // switch on pinDevid7 smoke alarm not sounding
  {
    if (DEBUG) {
      Serial.println("smoke alrm Off");
    }
    pinDevid7State = true;

    /* remove commenting to show period smoke alarm is off
    unsigned long currentDEVID8Millis = millis(); // Millis value when "smoke alarm not sounding"
    DEVID8interval = currentDEVID8Millis - prevDEVID8Millis; // Time in mseconds between smoke alarm going to off state

    prevDEVID8Millis = currentDEVID8Millis; // resets Millis value to current value
    Serial.print("DEVID8 smoke alarm off interval ");
    Serial.println(DEVID8interval);
    smokeinterval = DEVID7interval - DEVID8interval;
    Serial.print("Smoke Interval =  ");
    Serial.println(smokeinterval);
    */
    //sendToPushingBox(DEVID7); //Deactivated
  }
  if (digitalRead(pinDevid7) == LOW && pinDevid7State == true) // switch on pinDevid7 smoke alarm sounding
  {
    if (DEBUG) {
      Serial.println("smoke alarm ON");
    }
    pinDevid7State = false;


    unsigned long currentDEVID7Millis = millis(); // Millis value when "burglar alarm sounded"
    DEVID7interval = currentDEVID7Millis - prevDEVID7Millis; // Time in mseconds between smoke alarm sounder "chirps"

    prevDEVID7Millis = currentDEVID7Millis; // resets Millis value to current value
    // uncomment to show smoke alarm chirp intervals
   // Serial.print("DEVID7 smoke alarm on interval ");
   // Serial.println(DEVID7interval);
    
    if (DEVID7interval > 2000 ) // If "smoke alarm " is sounding greater than 2seconds (fault chirp) then DEVID7 is not sent

    {

      smoke = true; // enable only if sounder has not gone off more than 2 seconds ago alert not sent for smoke alarm low batt etc
                    // picks up 45 sec fault sounder chirps when fault or low battery found
      Serial.println("Time between chirps too long Smoke Alarm Fault or Batt low");
    }


    


    else if (DEVID7interval < 300) // alert not sent is rapid signal detected (poss wiring fault)
    {
      Serial.println("smoke alm sounder interval < 300mS");

    }




    else if (DEVID7interval > 300 && DEVID7interval < 2000 && smoke == true || smokepwr == false) // if smoke alarm sounder chirps >300ms or <2sec alert sent
      // normally smoke alarm sounder chirps 3 times every 500ms with a 1.5 sec break
    {

      //Sending request to PushingBox when the smoke alarm is sounding
      sendToPushingBox(DEVID7);    // request sent to PushingBox
      smokepwr = true; // smoke alarm sounding elapsed time is now enabled
      smokeActvated = true; // sets condition for sensing smoke alarm sound deactivating //*******************************************
      smoke = false; // stops smoke alarm repeat sounding restes once no sounder for more than 40 seconds
      Serial.println("Smoke Alarm Sounder Activated");
    }







  }





  // End Smoke alarm~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~










  //DEBUG part
  // this write the respons from PushingBox Server.
  // You should see a "200 OK"
  if (client.available()) {
    char c = client.read();
    if (DEBUG) {
      Serial.print(c);
    }
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
    if (DEBUG) {
      Serial.println();
    }
    if (DEBUG) {
      Serial.println("disconnecting.");
    }
    client.stop();
  }
  lastConnected = client.connected();
}


//Function for sending the request to PushingBox
void sendToPushingBox(char devid[]) {
  client.stop();
  if (DEBUG) {
    Serial.println("connecting...");
  }

  if (client.connect(serverName, 80)) {
    if (DEBUG) {
      Serial.println("connected");
    }

    if (DEBUG) {
      Serial.println("sendind request");
    }
    client.print("GET /pushingbox?devid=");
    client.print(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();


  }
  else {
    if (DEBUG) {
      Serial.println("connection failed");
    }

  }




}






//Function for sending the request to PushingBox
void sendToPushingBoxPower(char devid[]) {
  client.stop();
  if (DEBUG) {
    Serial.println("power restored connecting...");
  }

  if (client.connect(serverName, 80)) {
    if (DEBUG) {
      Serial.println("connected");
    }

    if (DEBUG) {
      Serial.println("sendind request power restored");
    }
    client.print("GET /pushingbox?devid=");
    client.print(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();



  }
  else {
    if (DEBUG) {
      Serial.println("connection failed trying again");
    }
    // if initial connection times out keep resending request to PushingBox on 1st power up untill success
    sendToPushingBoxPower(DEVID3);    //On power up runs Power restored scenario
  }




}