1

Please check the arduino program given below and help me to find out error. The program is for following hardware. GSM 800 module Arduino Uno board Limit switch(2)

We place two limit switch at main door & back door as main door is open the message will be send that is Main door is open & when it closed it will send message Main door is closed. This is same for Back door also.

We run this program & it run but it sends the massage repeatedly after some time. Please help me to find out error..

    const int Main = 7;
    const int Store = 8;
    const int Main_led =  13;
    const int Store_led =  14;
    bool i = false;
    bool j = false;
    bool k = false;
    bool l = false;
    int buttonState1 = 0;
    int buttonState2 = 0;
    void setup() {

      Serial.begin(9600);
      pinMode(Main_led, OUTPUT);
      pinMode(Store_led, OUTPUT);
      pinMode(Main, INPUT);
      pinMode(Store, INPUT);
    }

    void loop() {
      buttonState1 = digitalRead(Main);
      if (buttonState1 == HIGH && i == false ) {
        digitalWrite(Main_led, HIGH);
        Serial.println("OK");
        delay(1000);
        Serial.print("AT+CMGF=1\r\n");
        delay(500);
        Serial.print("AT+CMGS=\"+91-------------");
        Serial.print("\"\r\n");
        delay(5000);
        Serial.print("Main Door is closed");
        Serial.write(0x1A);
        delay(5000);
        i = true;
        j = false;
      }
      else
      { if (buttonState1 == LOW && j == false )

        { digitalWrite(Main_led, LOW);
          Serial.println("OK");
          delay(1000);
          Serial.print("AT+CMGF=1\r\n");
          delay(500);
          Serial.print("AT+CMGS=\"");
          Serial.print("+91---------------");
          Serial.print("\"\r\n");
          delay(5000);
          Serial.print("Main Door is open");
          Serial.write(0x1A);
          delay(5000);
          i = false;
          j = true;
        }
      }

      buttonState2 = digitalRead(Store);
      if (buttonState2 == HIGH && k == false) {

        digitalWrite(Store_led, HIGH);
        Serial.println("OK");
        delay(1000);
        Serial.print("AT+CMGF=1\r\n");
        delay(500);
        Serial.print("AT+CMGS=\"");
        Serial.print("+91-------------");
        Serial.print("\"\r\n");
        delay(5000);
        Serial.print("Store room is Closed");
        Serial.write(0x1A);
        delay(5000);
        k = true;
        l = false;
      }
      else
      { if (buttonState2 == LOW && l == false)
        {
          digitalWrite(Store_led, LOW);
          Serial.println("OK");
          delay(1000);
          Serial.print("AT+CMGF=1\r\n");
          delay(500);
          Serial.print("AT+CMGS=\"");
          Serial.print("+91------------------");
          Serial.print("\"\r\n");
          delay(5000);
          Serial.print("Store room is Open");
          Serial.write(0x1A);
          delay(5000);
          k = false;
          l = true;
        }
      }
    }
3
  • To avoid duplication of effort here's a link the exact same question posted on the electronics site: electronics.stackexchange.com/questions/290062/… Commented Mar 3, 2017 at 12:43
  • what if the door is open less than 11.5 seconds? Commented Mar 3, 2017 at 19:50
  • @dandavis message does not repeated . Commented Mar 6, 2017 at 5:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.