Send TXT via button press

I have a small problem with this project

https://create.arduino.cc/projecthub/SurtrTech/send-sms-text-from-arduino-using-sim800l-gsm-gprs-module-228975

It works as it should apart form my switch will be permanently set (pressed) but the code continuously send's txt after txt and I only want 1 txt sending

Any help much appreciated

The OP's code

/* This code works with Sim800L and a push button
 * Press the button to send a simple SMS/Text to a specified phone number
 * Refer to www.SurtrTech.com for more details
 */

#include <SoftwareSerial.h>

SoftwareSerial sim800l(2, 3); // RX,TX for Arduino and for the module it's TXD RXD, they should be inverted

#define button1 7 //Button pin, on the other pin it's wired with GND

bool button_State; //Button state


void setup()
{
  pinMode(button1, INPUT_PULLUP); //The button is always on HIGH level, when pressed it goes LOW
  sim800l.begin(9600);   //Module baude rate, this is on max, it depends on the version
  Serial.begin(9600);
  delay(1000);
}

void loop()
{
  button_State = digitalRead(button1);   //We are constantly reading the button State
  if (button_State == LOW)              //And if it's pressed
  {
    Serial.println("Button pressed");   //Shows this message on the serial monitor
    delay(200);                         //Small delay to avoid detecting the button press many times
    SendSMS();                          //And this function is called
  }
  if (sim800l.available())             //Displays on the serial monitor if there's a communication from the module
  {
    Serial.write(sim800l.read());
  }
}

void SendSMS()
{
  Serial.println("Sending SMS...");               //Show this message on serial monitor
  sim800l.print("AT+CMGF=1\r");                   //Set the module to SMS mode
  delay(100);
  sim800l.print("AT+CMGS=\"+*********\"\r");  //Your phone number don't forget to include your country code, example +212123456789"
  delay(500);
  sim800l.print("SIM800l is working");       //This is the text to send to the phone number, don't make it too long or you have to modify the SoftwareSerial buffer
  delay(500);
  sim800l.print((char)26);// (required according to the datasheet)
  delay(500);
  sim800l.println();
  Serial.println("Text Sent.");
  delay(500);
}

As written the program sends an SMS while the button is pressed, so if it is held down then multiple SMSs will be sent. If you detect when the button becomes pressed rather than when it is pressed it will send one SMS per press, if that is what you want

See the StateChangeDetection example in the IDE

Thanks for the reply

What im after is for the Arduino Nano to send 1 txt message when power up

Been in touch with the guy I making these for and he wants 1 txt every 12hrs so just added a delay off 43200000 to the end off the code

holdingpattern:
Ewwwww.

Pin 7 to permanent gnd
delay(43200000); last line off code

IanSuggy:
Pin 7 to permanent gnd

Why?

aarg:
Why?

The only way I know how to do it

IanSuggy:
The only way I know how to do it

That was not the question. The question is why do you need to do it at all?

Friend wants to know when something is caught in his trap so he can go and retrieve it. His aim is to get to the location within the 12hr delay in sending the next TXT, he would then re-set the trap