interrupts with conditions

I have Just started to learn interrupts with a simple example... ( http://arduino.cc/en/Reference/AttachInterrupt )

int pin = 13;
volatile int state = LOW;

void setup()
{
  pinMode(pin, OUTPUT);
  attachInterrupt(0, blink, CHANGE);
}

void loop()
{
  digitalWrite(pin, state);
}

void blink()
{
  state = !state;
}

But the explanation is not there. I found another tutorial about interrupts... ( http://www.davidorlo.com/articles/arduino/arduino-–-interrupt-tutorial-with-led-switch )

/*
Advanced Blink with an Interrupt Sketch
By: David M. Orlo
www.DaviedOrlo.com
*/
byte SWITCHPIN=2; //Set Pin 2 as Switch
byte LEDPIN=6; //Set Pin 6 as LED
byte brightness; //Create a Integer variable named brightness
byte delayedoff; //Create a Integer variable named delayedoff
byte delayedon; //Create a Integer variable named delayedon
//If you want to go higher than 255 you must change from "byte" to "int"
volatile boolean trigger=LOW; //This is our interrupt connected to the button switch
 
void setup(){
  attachInterrupt(0, interrupttrigger, LOW); //Interrupt 0 is Digital Pin 2
  //When the Input goes from High to Low it will trigger a function called crazyLED
  pinMode(LEDPIN, OUTPUT); //Set Pin 6 as Output
}
 
void loop(){
  delay(200); //Wait a moment to help debounce the switch
  if (trigger==1){ //Check to see if the interrupt was triggered
    crazyLED();} //Enter our LED blinking function
  else{ //If the button was pressed again
    analogWrite(LEDPIN, 0);} //Turn the LED off
}
 
void crazyLED(){
  delay(200); //Wait a moment to help debounce the switch
  while(trigger == HIGH){ //Will run this loop until the interrupt value changes
    brightness = random(1, 254); //Generates a random number from 1-254 and assigns it to the variable named brightness
    delayedoff = random(1, 125); //A random amount of time the LED is turned off
    delayedon = random(1, 250); //A random amount of time the LED is turned on
    analogWrite(LEDPIN, brightness); //Uses the random number we generated to write the value to our LED
    delay(delayedon); //random delay on time
    analogWrite(LEDPIN, 0); //We turn the LED off for a blinking effect
    delay(delayedoff);} //Random delay off time
}
 
void interrupttrigger(){ //When the switch is pressed (Interrupt is triggered) the arduino enters this function
  if (trigger ==LOW){ //Checks to see what the last value was (high or low)
    trigger=HIGH;} //If its low it is now set to high
  else{
    trigger=LOW;} //If its high it is now set to low
}

I cannot understand the interrupt setup here

volatile boolean trigger=LOW; //This is our interrupt connected to the button switch

why is it stated LOW? Is it the interrupt MODE or something else...?

I want to use the RISING mode. Kindly explain the Arduino interrupt example with // "comments"

With the first example how did you have the button attached to the uno and to which pin (hint not pin 0). You LED should turn on when the button is pressed and off otherwise.

Mark

http://arduino.cc/en/Reference/AttachInterrupt

helped me understand it a bit better

"trigger" is just a boolean variable that is being initialized to LOW. The comment is confusing you. The real interrupt routine is at the bottom and is named "interrupttrigger()". It is installed by the call to attachInterrupt(). The trigger mode is specified as one of the arguments to the attachInterrupt() function.

Hi, afremont it's right. There is one of rules of the use of interrupts. See reference. There are three rules very important:

1.- All variables wich value is changed at interrupt function, should be declares as volatile.
2.- The functions delay() don't work and millis() don't increment his value inside the interrupt function.
3.- The comunication by serial can lost data.

This is beacause the code use a variable TRIGGER. In the first code this variable is "volatile int state". You look the changes on value of this variables in the loop and change it in the interrupt function. When the value has changed you go to the function that you want.

I hope thats helps.

Thanks to all for your generous support.

In the second code what is the difference between trigger==1 & trigger==HIGH ?

3.- The comunication by serial can lost data.

No, it can't.

What can happen is that the buffer fills up, so Serial.print() blocks waiting for there to be room to add more data. That will happen only when some data has been shifted out. But, since that requires interrupts to happen, and interrupts don't happen while an ISR is running, there will never be more room in the buffer, Serial.print() will block forever, waiting for something to happen that can not happen.

..........
............
volatile int trigger=LOW
.........

void setup()
{
attachInterrupt(0, interrupttrigger, RISING);
............
.................
}

void loop(){
  delay(200); //Wait a moment to help debounce the switch
  if (trigger==1){ //Check to see if the interrupt was triggered
    crazyLED();} 

else{
}

does the trigger==1 mean the interrupt will run if the trigger is low? (when I press the button the arduino sees low?)

nightcrawler218:
Thanks to all for your generous support.

In the second code what is the difference between trigger==1 & trigger==HIGH ?

LOW is zero
HIGH is non-zero

  if (trigger ==LOW){ //Checks to see what the last value was (high or low)
    trigger=HIGH;} //If its low it is now set to high
  else{
    trigger=LOW;} //If its high it is now set to low

A shorter way to do that is to use bitwise XOR logic (operates of ALL the bits so use 0 and 1)
The XOR symbol is ^.
A ^ B == 1 if A and B are different or 0 if they are the same.

To flip a 1 or 0, XOR it with 1
1 XOR 1 = 0
0 XOR 1 = 1

trigger = trigger ^ 1;

And we can shorten it further using ^= that below XOR's trigger and 1 leaving the result in trigger.

trigger ^= 1;

That 1 short line does the same as the if-else above in 1 cycle if 'trigger' is held in a register.

I'm not certain that the compiler doesn't see the if-else and compile the short version anyway.

Thanks GFS for your post...
:slight_smile:

If you are unsure and want answers right then, the best way is to make a very simple sketch that tests and prints only what you want.

Quickest way is to load a minimal Example in the IDE like BareMinimum or DigitalReadSerial and get rid of the lines you don't need then add in your test.

DigitalReadSerial:

/*
  DigitalReadSerial
 Reads a digital input on pin 2, prints the result to the serial monitor 
 
 This example code is in the public domain.
 */

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
}

void loop() {
  int sensorValue = digitalRead(2);
  Serial.println(sensorValue, DEC);
  delay(50);
}

Edited down with only a few cuts and in seconds you have shell.. save on typing:

void setup() {
  Serial.begin(9600);
}

void loop() {
}

And then to test:

void setup() {
  Serial.begin(9600);

  byte  test = LOW;
  Serial.println( test, DEC );
  test = HIGH; // this is copy & paste then edit the 2 lines above
  Serial.println( test, DEC );
}

void loop() {
}

Run that and you will know as quickly as you can post the question, quicker than anyone can reply.
XD

#include <SoftwareSerial.h>
 


String msg = String("");
int SmsContentFlag = 0;
//control pins of relay.
int relay_a=4;
int relay_b=5;
int relay_c=6;
int relay_d=7;
int led = 13; // Interrupt monitor
int door = 12; // Door status monitor
int button=2; // door sensor monitor
 
void setup()
{
  Serial.begin(9600);                 // the GPRS baud rate
  // Initialize  PINs
  pinMode( 4, OUTPUT ); 
  pinMode( 5, OUTPUT ); 
  pinMode( 6, OUTPUT ); 
  pinMode( 7, OUTPUT ); 
  digitalWrite( 4, LOW ); 
  digitalWrite( 5, LOW ); 
  digitalWrite( 6, LOW );
  digitalWrite( 7, LOW );
  pinMode(13, OUTPUT); // Interrupt monitor
  pinMode(12, INPUT); // Door status monitor
  pinMode(2, INPUT); //Door sensor monitor
  Serial.println( "AT+CMGF=1" ); 
  delay(200);
}
 
void loop()
{
   char SerialInByte;
    if(Serial.available())
    {       
        SerialInByte = (unsigned char)Serial.read();
       delay(5);
                // -------------------------------------------------------------------
        // EN: Program also listen to the GPRS shield message.
        // -------------------------------------------------------------------
       // EN: If the message ends with <CR> then process the message
        if( SerialInByte == 13 ){
          // EN: Store the char into the message buffer
          ProcessGprsMsg();
         }
         if( SerialInByte == 10 ){
            // EN: Skip Line feed
         }
         else {
           // EN: store the current character in the message string buffer
           msg += String(SerialInByte);
         }
     }   
}
// EN: Make action based on the content of the SMS. 
//     Notice than SMS content is the result of the processing of several GPRS shield messages.
void ProcessSms( String sms ){
  
  if( sms.indexOf("ona") >= 0 ){
    digitalWrite( relay_a, HIGH );
  }
   if( sms.indexOf("onb") >= 0 ){
    digitalWrite(  relay_b, HIGH );
  }
   if( sms.indexOf("onc") >= 0 ){
    digitalWrite(  relay_c, HIGH );
  }
  if( sms.indexOf("ond") >= 0 ){
    digitalWrite(  relay_d, HIGH );
  }
  if( sms.indexOf("offa") >= 0 ){
    digitalWrite(  relay_a, LOW );
  }
  if( sms.indexOf("offb") >= 0 ){
    digitalWrite(  relay_b, LOW );
  }
  if( sms.indexOf("offc") >= 0 ){
    digitalWrite(  relay_c, LOW );
  }
  if( sms.indexOf("offd") >= 0 ){
    digitalWrite(  relay_d, LOW );
  }
}
// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS(){
  Serial.println( "AT+CMGF=1" );
}

void GprsReadSmsStore( String SmsStorePos ){
  Serial.print( "AT+CMGR=" );
  Serial.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
  msg = "";
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
  if( msg.indexOf( "Call Ready" ) >= 0 ){
   //  Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
     GprsTextModeSMS();
  }
  
  // EN: unsolicited message received when getting a SMS message
  if( msg.indexOf( "+CMTI" ) >= 0 ){
   //  Serial.println( "*** SMS Received ***" );
     // EN: Look for the coma in the full message (+CMTI: "SM",6)
     //     In the sample, the SMS is stored at position 6
     int iPos = msg.indexOf( "," );
     String SmsStorePos = msg.substring( iPos+1 );
   //  Serial.print( "SMS stored at " );
  //   Serial.println( SmsStorePos );     
     // EN: Ask to read the SMS store
     GprsReadSmsStore( SmsStorePos );
  }
  
  // EN: SMS store readed through UART (result of GprsReadSmsStore request)  
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
    // EN: Next message will contains the BODY of SMS
    SmsContentFlag = 1;
    // EN: Following lines are essentiel to not clear the flag!
    ClearGprsMsg();
    return;
  }
  
  // EN: +CMGR message just before indicate that the following GRPS Shield message 
  //     (this message) will contains the SMS body 
  if( SmsContentFlag == 1 ){
 //   Serial.println( "*** SMS MESSAGE CONTENT ***" );
 //   Serial.println( msg );
 //   Serial.println( "*** END OF SMS MESSAGE ***" );
    ProcessSms( msg );
  }
  
  ClearGprsMsg();
  // EN: Always clear the flag
  SmsContentFlag = 0; 
}

now in this code I want to attach a function. If I send "ona" relay 1(Door Lock) is ON. I have attached a magnetic door sensor that sees HIGH when the door is locked & the sensor has no connection with the "door lock".

http://img23.imageshack.us/img23/2820/doorlw.jpg

Now I want that if the door lock is activated & the sensor value is changed pin13 will glow. Should I need interrupts for that..? If so then how to program the interrupt ONLY IF the relay1 is activated..?

Should I need interrupts for that..?

No.

I have modified the code & hardware too. digital pin 5(relay control, OUTPUT PIN) & digital pin2 (door lock monitor, INPUT) will be shorted so that if the relay is ON the door lock monitor is also on. Now the problem arises I have added the door monitor logic into the void loop() function. Two functio will be in the loop() function.

if pin2 is HIGH> check for the status of door sensor> if door sensor detects any change, switch on the buzzer/led

check for new sms> process sms> actuate the relays

#include <SoftwareSerial.h>
 

// EN: String buffer for the GPRS shield message
String msg = String("");
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
int SmsContentFlag = 0;
//control pins of relay.
int relay_a=4;
int relay_b=5;
int relay_c=6;
int relay_d=7;
int dlm=2; // door lock monitor
int door_sensor=3;  // door sensor
int led=13;
// EN: Code PIN of the SIM card (if applied)
//String SIM_PIN_CODE = String( "XXXX" );
 
void setup()
{
  Serial.begin(19200);                 // the GPRS baud rate
  // Initialize  PINs
  pinMode( 4, OUTPUT ); 
  pinMode( 5, OUTPUT ); 
  pinMode( 6, OUTPUT ); 
  pinMode( 7, OUTPUT ); 
  pinMode( 2, INPUT );
  pinMode( 3,INPUT );
  pinMode( 13, OUTPUT );
  digitalWrite( 4, LOW ); 
  digitalWrite( 5, LOW ); 
  digitalWrite( 6, LOW );
  digitalWrite( 7, LOW );
  Serial.println( "AT+CMGF=1" ); 
  delay(200);
}
 
void loop()
{
 {
  if (digitalRead(2,HIGH))
  {
     if (digitalRead(3,HIGH)
     {
       (digitalWrite(13,HIGH)
     }
  }
     else{
   }
 }
  
    char SerialInByte;
    if(Serial.available())
    {       
        SerialInByte = (unsigned char)Serial.read();
       delay(5);
        
        // -------------------------------------------------------------------
        // EN: Program also listen to the GPRS shield message.
        // -------------------------------------------------------------------
       // EN: If the message ends with <CR> then process the message
        if( SerialInByte == 13 ){
          // EN: Store the char into the message buffer
          ProcessGprsMsg();
         }
         if( SerialInByte == 10 ){
            // EN: Skip Line feed
         }
         else {
           // EN: store the current character in the message string buffer
           msg += String(SerialInByte);
         }
     }   
}
// EN: Make action based on the content of the SMS. 
//     Notice than SMS content is the result of the processing of several GPRS shield messages.
void ProcessSms( String sms ){
  
  if( sms.indexOf("ona") >= 0 ){
    digitalWrite( relay_a, HIGH );
  }
   if( sms.indexOf("onb") >= 0 ){
    digitalWrite(  relay_b, HIGH );
  }
   if( sms.indexOf("onc") >= 0 ){
    digitalWrite(  relay_c, HIGH );
  }
  if( sms.indexOf("ond") >= 0 ){
    digitalWrite(  relay_d, HIGH );
  }
  if( sms.indexOf("offa") >= 0 ){
    digitalWrite(  relay_a, LOW );
  }
  if( sms.indexOf("offb") >= 0 ){
    digitalWrite(  relay_b, LOW );
  }
  if( sms.indexOf("offc") >= 0 ){
    digitalWrite(  relay_c, LOW );
  }
  if( sms.indexOf("offd") >= 0 ){
    digitalWrite(  relay_d, LOW );
  }
}
// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS(){
  Serial.println( "AT+CMGF=1" );
}

void GprsReadSmsStore( String SmsStorePos ){
  Serial.print( "AT+CMGR=" );
  Serial.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
  msg = "";
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
  if( msg.indexOf( "Call Ready" ) >= 0 ){
   //  Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
     GprsTextModeSMS();
  }
  
  // EN: unsolicited message received when getting a SMS message
  if( msg.indexOf( "+CMTI" ) >= 0 ){
   //  Serial.println( "*** SMS Received ***" );
     // EN: Look for the coma in the full message (+CMTI: "SM",6)
     //     In the sample, the SMS is stored at position 6
     int iPos = msg.indexOf( "," );
     String SmsStorePos = msg.substring( iPos+1 );
   //  Serial.print( "SMS stored at " );
  //   Serial.println( SmsStorePos );     
     // EN: Ask to read the SMS store
     GprsReadSmsStore( SmsStorePos );
  }
  
  // EN: SMS store readed through UART (result of GprsReadSmsStore request)  
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
    // EN: Next message will contains the BODY of SMS
    SmsContentFlag = 1;
    // EN: Following lines are essentiel to not clear the flag!
    ClearGprsMsg();
    return;
  }
  
  // EN: +CMGR message just before indicate that the following GRPS Shield message 
  //     (this message) will contains the SMS body 
  if( SmsContentFlag == 1 ){
 //   Serial.println( "*** SMS MESSAGE CONTENT ***" );
 //   Serial.println( msg );
 //   Serial.println( "*** END OF SMS MESSAGE ***" );
    ProcessSms( msg );
  }
  
  ClearGprsMsg();
  // EN: Always clear the flag
  SmsContentFlag = 0; 
}

In this code the void loop shows error.

C:\Users\User\Desktop\arduino-1.5.2\hardware\arduino\avr\cores\arduino/Arduino.h: In function 'void loop()':
C:\Users\User\Desktop\arduino-1.5.2\hardware\arduino\avr\cores\arduino/Arduino.h:102: error: too many arguments to function 'int digitalRead(uint8_t)'
Using_SMS_to_Control_Relay_Hardware_Serial:41: error: at this point in file
C:\Users\User\Desktop\arduino-1.5.2\hardware\arduino\avr\cores\arduino/Arduino.h:102: error: too many arguments to function 'int digitalRead(uint8_t)'
Using_SMS_to_Control_Relay_Hardware_Serial:43: error: at this point in file
Using_SMS_to_Control_Relay_Hardware_Serial:44: error: expected `)' before '{' token
Using_SMS_to_Control_Relay_Hardware_Serial:47: error: expected primary-expression before '}' token
Using_SMS_to_Control_Relay_Hardware_Serial:47: error: expected `;' before '}' token

Actually I want yo attach an interrupt function that can ONLY be activated when the door lock monitor (pin 2) is high & the door sensor detects a change (preferably Falling trigger).

#include <avr/interrupt.h>
volatile int doorlock;

void setup(){
pinMode(2,INPUT);
digitalWrite(2,HIGH);
attachInterrupt(0, doordoingsomething, FALLING);  // or attachInterrupt(0, doordoingsomething, RISING); or attachInterrupt(0, doordoingsomething, CHANGE);
doorlock = 0
// other setup
interrupts();  // starts the int's
}
void loop(){ 
if (doorlock == 1){  // if this = 1 then int has fired
alarmneedstohappen();
}
// normal loop stuff
}

void doordoingsomething();
doorlock=1; // sets flag to 1 so loop if catches it
}

void alarmneedstohappen();{
// we are here because int flag happened.
doorlock = 0 // reset int flag
// perform other alarm stuff of whatever
}

nightcrawler218:
I have modified the code & hardware too. digital pin 5(relay control, OUTPUT PIN) & digital pin2 (door lock monitor, INPUT) will be shorted so that if the relay is ON the door lock monitor is also on. Now the problem arises I have added the door monitor logic into the void loop() function. Two functio will be in the loop() function.

if pin2 is HIGH> check for the status of door sensor> if door sensor detects any change, switch on the buzzer/led

check for new sms> process sms> actuate the relays

#include <SoftwareSerial.h>

// EN: String buffer for the GPRS shield message
String msg = String("");
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
int SmsContentFlag = 0;
//control pins of relay.
int relay_a=4;
int relay_b=5;
int relay_c=6;
int relay_d=7;
int dlm=2; // door lock monitor
int door_sensor=3;  // door sensor
int led=13;
// EN: Code PIN of the SIM card (if applied)
//String SIM_PIN_CODE = String( "XXXX" );

void setup()
{
  Serial.begin(19200);                 // the GPRS baud rate
  // Initialize  PINs
  pinMode( 4, OUTPUT );
  pinMode( 5, OUTPUT );
  pinMode( 6, OUTPUT );
  pinMode( 7, OUTPUT );
  pinMode( 2, INPUT );
  pinMode( 3,INPUT );
  pinMode( 13, OUTPUT );
  digitalWrite( 4, LOW );
  digitalWrite( 5, LOW );
  digitalWrite( 6, LOW );
  digitalWrite( 7, LOW );
  Serial.println( "AT+CMGF=1" );
  delay(200);
}

void loop()
{
{
  if (digitalRead(2,HIGH))
  {
     if (digitalRead(3,HIGH)
     {
       (digitalWrite(13,HIGH)
     }
  }
     else{
   }
}
 
    char SerialInByte;
    if(Serial.available())
    {       
        SerialInByte = (unsigned char)Serial.read();
       delay(5);
       
        // -------------------------------------------------------------------
        // EN: Program also listen to the GPRS shield message.
        // -------------------------------------------------------------------
       // EN: If the message ends with then process the message
        if( SerialInByte == 13 ){
          // EN: Store the char into the message buffer
          ProcessGprsMsg();
         }
         if( SerialInByte == 10 ){
            // EN: Skip Line feed
         }
         else {
           // EN: store the current character in the message string buffer
           msg += String(SerialInByte);
         }
     }   
}
// EN: Make action based on the content of the SMS.
//     Notice than SMS content is the result of the processing of several GPRS shield messages.
void ProcessSms( String sms ){
 
  if( sms.indexOf("ona") >= 0 ){
    digitalWrite( relay_a, HIGH );
  }
   if( sms.indexOf("onb") >= 0 ){
    digitalWrite(  relay_b, HIGH );
  }
   if( sms.indexOf("onc") >= 0 ){
    digitalWrite(  relay_c, HIGH );
  }
  if( sms.indexOf("ond") >= 0 ){
    digitalWrite(  relay_d, HIGH );
  }
  if( sms.indexOf("offa") >= 0 ){
    digitalWrite(  relay_a, LOW );
  }
  if( sms.indexOf("offb") >= 0 ){
    digitalWrite(  relay_b, LOW );
  }
  if( sms.indexOf("offc") >= 0 ){
    digitalWrite(  relay_c, LOW );
  }
  if( sms.indexOf("offd") >= 0 ){
    digitalWrite(  relay_d, LOW );
  }
}
// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS(){
  Serial.println( "AT+CMGF=1" );
}

void GprsReadSmsStore( String SmsStorePos ){
  Serial.print( "AT+CMGR=" );
  Serial.println( SmsStorePos );
}

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
  msg = "";
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
  if( msg.indexOf( "Call Ready" ) >= 0 ){
   //  Serial.println( "*** GPRS Shield registered on Mobile Network " );
     GprsTextModeSMS();
  }
 
  // EN: unsolicited message received when getting a SMS message
  if( msg.indexOf( "+CMTI" ) >= 0 ){
   //  Serial.println( "
SMS Received " );
     // EN: Look for the coma in the full message (+CMTI: "SM",6)
     //     In the sample, the SMS is stored at position 6
     int iPos = msg.indexOf( "," );
     String SmsStorePos = msg.substring( iPos+1 );
   //  Serial.print( "SMS stored at " );
  //   Serial.println( SmsStorePos );     
     // EN: Ask to read the SMS store
     GprsReadSmsStore( SmsStorePos );
  }
 
  // EN: SMS store readed through UART (result of GprsReadSmsStore request) 
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
    // EN: Next message will contains the BODY of SMS
    SmsContentFlag = 1;
    // EN: Following lines are essentiel to not clear the flag!
    ClearGprsMsg();
    return;
  }
 
  // EN: +CMGR message just before indicate that the following GRPS Shield message
  //     (this message) will contains the SMS body
  if( SmsContentFlag == 1 ){
//   Serial.println( "
SMS MESSAGE CONTENT " );
//   Serial.println( msg );
//   Serial.println( "
END OF SMS MESSAGE ***" );
    ProcessSms( msg );
  }
 
  ClearGprsMsg();
  // EN: Always clear the flag
  SmsContentFlag = 0;
}




In this code the void loop shows error. 


~~~
C:\Users\User\Desktop\arduino-1.5.2\hardware\arduino\avr\cores\arduino/Arduino.h: In function 'void loop()':

C:\Users\User\Desktop\arduino-1.5.2\hardware\arduino\avr\cores\arduino/Arduino.h:102: error: too many arguments to function 'int digitalRead(uint8_t)'
Using_SMS_to_Control_Relay_Hardware_Serial:41: error: at this point in file
C:\Users\User\Desktop\arduino-1.5.2\hardware\arduino\avr\cores\arduino/Arduino.h:102: error: too many arguments to function 'int digitalRead(uint8_t)'
Using_SMS_to_Control_Relay_Hardware_Serial:43: error: at this point in file
Using_SMS_to_Control_Relay_Hardware_Serial:44: error: expected )' before '{' token Using_SMS_to_Control_Relay_Hardware_Serial:47: error: expected primary-expression before '}' token Using_SMS_to_Control_Relay_Hardware_Serial:47: error: expected ;' before '}' token




Actually I want yo attach an interrupt function that can ONLY be activated when the door lock monitor (pin 2) is high & the door sensor detects a change (preferably Falling trigger).

From what I can see you want to add increasing complexity to get around your shortcomings in understanding code. It is like spinning the wheels in mud, you only get stuck deeper.

Read about if-else and switch-case and practice on simple examples. Then find a clear explanation on finite state machines. Proper tools and the understanding of how to use them will give you a clear view of far easier ways.

You do not need interrupts for something so slow as button press. If your code does not prevent itself from being responsive, 1 millisecond to Arduino is like whole minutes to you.

  if (digitalRead(2,HIGH))

do you mean

  if (digitalRead(2) == HIGH)

Actually I want yo attach an interrupt function that can ONLY be activated when the door lock monitor (pin 2) is high & the door sensor detects a change (preferably Falling trigger).

Why do you insist on using an interrupt? I don't see why you need an interrupt.

In any case, you can attach the interrupt handler when the pin goes high (NOT IS high), and detach it when the pin goes low (NOT IS low).

  if (digitalRead(2,HIGH))

Have you seen, anywhere, any one else try to misuse digitalRead() this way?

The digitalRead() function takes ONE argument, the pin to read from. It returns a value - HIGH or LOW. You have to compare the return value to HIGH or LOW:

  if (digitalRead(2) == HIGH)
     if (digitalRead(3,HIGH)

The correct ratio of close parens to open parens is 1 to 1. Any other ratio is WRONG!

       (digitalWrite(13,HIGH)

Why is there a ( at the beginning of this statement? Why is there NOT a ; at the end?