# Sim800 push button to send messsage

**URL:** <https://forum.arduino.cc/t/sim800-push-button-to-send-messsage/412208>\
**Category:** Programming\
**Created:** [October 10, 2016, 1:55am UTC](https://forum.arduino.cc/t/sim800-push-button-to-send-messsage/412208 "2016-10-10T01:55:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom1wiseman](https://avatars.discourse-cdn.com/v4/letter/t/5e9695/32.png) [@tom1wiseman](https://forum.arduino.cc/u/tom1wiseman)\
**Post date:** [October 10, 2016, 1:55am UTC](https://forum.arduino.cc/t/sim800-push-button-to-send-messsage/412208/1 "2016-10-10T01:55:19Z")

</div>

Hello, my first post.

I am simply (in theory) wanting to send one of three pre-selected messages when one of three buttons are pressed. (3 buttons to send 3 different messages and one LED to alert the message has been sent) See the attached code to look at what I have done so far...

my issue is using a push button (momentary) to add value to my three (defined at top);

int button1press  
int button2press  
int button3press

i know I need to do something like:

if b1pin = high  
button1press ++  
else

if b2pin = high  
button2press ++  
else

if b3pin = high  
button3press ++

or something like that... but I need help incorporating that into my code, I would really appreciate any help you could give. I have done most of the hard work I think it's just incorporating the above to trigger the code I already have attached.

Thanks in advance. 🙂

[SMS\_button\_sender.ino](https://forum.arduino.cc/uploads/short-url/f8olJeLFlqYLIF6v4n0uxQxnN85.ino) (1.93 KB)

---

<div class="post-metadata">

**Author:** ![tom1wiseman](https://avatars.discourse-cdn.com/v4/letter/t/5e9695/32.png) [@tom1wiseman](https://forum.arduino.cc/u/tom1wiseman)\
**Post date:** [October 10, 2016, 2:05am UTC](https://forum.arduino.cc/t/sim800-push-button-to-send-messsage/412208/2 "2016-10-10T02:05:13Z")

</div>

Hello, my first post.

I am simply (in theory) wanting to send one of three pre-selected messages when one of three buttons are pressed. (3 buttons to send 3 different messages and one LED to alert the message has been sent) See the attached code to look at what I have done so far...

my issue is using a push button (momentary) to add value to my three (defined at top);

int button1press  
int button2press  
int button3press

i know I need to do something like:

if b1pin = high  
button1press ++  
else

if b2pin = high  
button2press ++  
else

if b3pin = high  
button3press ++

or something like that... but I need help incorporating that into my code, I would really appreciate any help you could give. I have done most of the hard work I think it's just incorporating the above to trigger the code I already have attached.

Thanks in advance. 🙂

```cpp
#include <GSM.h>
 char remoteNumber[20]= "fjrglr"; //my arduino's phone number
#define PINNUMBER ""

int button1press = 0;   //holding values for trigering abtton press (need to add to these values when button press)
int button2press = 0;
int button3press = 0;

int ledPin = 13;  //LED will light for a few seconds when sms is sent.

int b1Pin = 5;  //button input pins
int b2Pin = 6;
int b3Pin = 7;

// initialize the library instance
GSM gsmAccess; 
GSM_SMS sms;

void setup(){

  pinMode(ledPin, OUTPUT);
  pinMode(b1Pin, INPUT); 
  pinMode(b2Pin, INPUT); 
  pinMode(b3Pin, INPUT); 
  
  // initialize serial communications
  Serial.begin(9600);
  

  Serial.println("SMS Messages Sender");

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
    sms.beginSMS(remoteNumber);
  sms.print("Test Message - GSM Connection OK... Transmissions have been requested to this number.");
  sms.endSMS(); 
}

void loop(){
  
  if(button1press > 0){
    sms.beginSMS(remoteNumber);
    sms.print("Button 1 has been Pressed");
    sms.endSMS(); 
    button1press = 0;
    digitalWrite(13, HIGH);   
    delay(3000);              
    digitalWrite(13, LOW);         
  }

  if(button2press > 0){
    sms.beginSMS(remoteNumber);
    sms.print("Button 2 has been Pressed");
    sms.endSMS(); 
    button2press = 0;
    digitalWrite(13, HIGH);   
    delay(3000);              
    digitalWrite(13, LOW);   
  }

  if(button3press > 0){
    sms.beginSMS(remoteNumber);
    sms.print("Button 3 has been Pressed");
    sms.endSMS(); 
    button3press = 0;
    digitalWrite(13, HIGH);   
    delay(3000);              
    digitalWrite(13, LOW);   
 
  } 
  }

```

---

<div class="post-metadata">

**Author:** ![sarouje](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sarouje](https://forum.arduino.cc/u/sarouje)\
**Post date:** [October 10, 2016, 4:58am UTC](https://forum.arduino.cc/t/sim800-push-button-to-send-messsage/412208/3 "2016-10-10T04:58:52Z")

</div>

From the code, I cant see any code that read the button Press.

You should do some thing like.

```cpp
void loop(){
  button1Press=digitalRead(b1Pin);
  button2Press = digitalRead(b2Pin);
  button3Press = digitalRead(b3Pin);

  if(button1Press==HIGH){
    //send sms 'button1 pressed'
    button1Press=LOW;
  }
  else if(button2Press==HIGH){
    //send sms 'button2 pressed'
    button2Press=LOW;
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 10:07pm UTC](https://forum.arduino.cc/t/sim800-push-button-to-send-messsage/412208/4 "2021-05-05T22:07:14Z")

</div>


