My button and Buzzer won't work together

Good day Mam/Sir

I am trying to create a device using Arduino pro mini that once the button were pushed it will trigger the buzzer and emergency text message will be sent.

My code is :

 #include <NeoSWSerial.h>
#include <AltSoftSerial.h>
NeoSWSerial MOD_GPS(2, 3);
#include <TinyGPS.h>
TinyGPS gps;
AltSoftSerial MOD_SIM800L(8, 9);
const byte armButtonPin = 6;              // Alarm on button
const byte disarmButtonPin = 7;          // Alarm  off button 
const byte Buzzer = 12;                       //Buzzer




float latitude, longitude;
unsigned long age;
unsigned long chars;


void setup()
{

  MOD_SIM800L.begin(9600);
  MOD_GPS.begin(9600);
  Serial.begin(9600);
  pinMode(armButtonPin, INPUT);
  pinMode(disarmButtonPin, INPUT);
  pinMode(Buzzer, OUTPUT); // Declare the push Buzzer pin as OUTPUT

  //Print on serial monitor:
  Serial.println("");
  Serial.println("Start");
  Serial.println("Sending Data ... ");
  Serial.println("");
}

void loop() {

  bool newData = false;
  unsigned long chars;
  unsigned short sentences, failed;
  for (unsigned long start = millis(); millis() - start < 1000;)
    while (MOD_GPS.available())
    {
      char c = MOD_GPS.read();
      if (gps.encode(c))
        newData = true;

      if (newData) {

        gps.f_get_position(&latitude, &longitude, &age);
        Serial.print(("Latitud/Longitud: "));
        Serial.println(" ");
        Serial.println(latitude == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : latitude, 7); Serial.println(", ");
        delay(1000);
        Serial.println(longitude == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : longitude, 7);
        gps.stats(&chars, &sentences, &failed);
        delay(1000);
        break;

        delay(1000);
      }
    }

  bool armbuttonState = digitalRead(armButtonPin); 
  if (armbuttonState == HIGH)
  {

  Serial.println("Configuration Done!");
  Serial.println("Sending SMS...");
  Serial.print("MeMOD_GPSage Sent!");
  MOD_SIM800L.println("AT+CMGF=1\r\n");
  delay(100);
  MOD_SIM800L.println("AT+CMGS=\"+628XXXXXXX\"\r\n");
  delay(100);
  MOD_SIM800L.println("\nI'm in Trouble! I need your help!!");
  MOD_SIM800L.println("\nhttp://maps.google.com/maps?q"); MOD_SIM800L.print(longitude == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : latitude, 5); MOD_SIM800L.print(","); MOD_SIM800L.print(longitude == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : longitude, 5);
  //Enviar Ctrl+Z
  MOD_SIM800L.write((char)26);
  digitalWrite(Buzzer, HIGH); //make a sound
  }

    bool disarmbuttonState = digitalRead(disarmButtonPin); 
    if (disarmbuttonState == HIGH)
      {    
      digitalWrite(Buzzer, LOW); //silent
    }

  delay(100);
  exit (0);

}

*sorry if its too messy .

It has 2 button that serves as an on/off switch for the buzzer, once I pushed the on switch the buzzer will alarm then a text will be sent unless I pushed the off switch the buzzer will continuously trigger a sound. I dont know how to do these using one switch only so I tried if it will work on two buttons like I what I saw on Google.

The problem is that after I inserted my code for button and buzzer it doesn't work anymore. Can anyone tell me what went wrong? I will really appreciate your help. Thank you

input pins need to be pulled up/down with software (code) or hardware( resistor ) or else the pin 'floats'

you can pull them up inside the code using pinMode(button_x,INPUT_PULLUP);

and then one terminal of your physical button (normally open) to be connected to that pin (button_x) , and the other to GND

if you have several input_buttons, just do the same for all

and then , in your loop, you can check for if ( digitalRead(button_x) == LOW ) { do_this(); } OR you could use interrupt() which is the best alternative

i don't know if i made myself clear

KASSIMSAMJI:
OR you could use interrupt() which is the best alternative

I wonder how many members here will agree with that assertion?

ardy_guy:
I wonder how many members here will agree with that assertion?

Nobody who knows what they're doing.

Hi,
Have you got some code that JUST does the button and buzzer function?

Forget the rest for the moment and do your code in STAGES.

First wire some code that JUST does the button and buzzer function.

Check here for a description of internal pullup.

Thanks.. Tom... :slight_smile:

Do you know what

 exit (0);

does?