Panic Switch Demo

I'm working on creating a panic button on my Arduino UNO board that will perform three functions. The functions are:

  • Sound an alarm when pressed
  • light up the led when pressed, and
  • give off signals or data when pressed.

Why I want the panic button to give off signals is because after I create this panic button, I'm thinking of creating a web page using php that can retrieve signals from the panic button when it is triggered.

I'm using a push button to act as a panic button, a led to light when the button is pressed, and a buzzer to give off a warning sound when the button is pressed.

With the help from some tutorials, I managed to get the led light and alarm siren working. Although, I'm new to using Arduino, and I'm not too sure how I can code the push button to send signals when it is pressed. I added something but I'm not sure if its okay. Please can someone go through this coding and tell me if its okay.

Below is the Arduino coding I'm using:

//set pin numbers

int ledPin = 12;
int buzzerPin = 13;
int buttonPin = 4;

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

  pinMode(ledPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(buttonPin, INPUT);

}

void loop() {

  if (digitalRead(buttonPin) == HIGH)
  {
    digitalWrite(ledPin, HIGH);
    delay(500);
    tone(buzzerPin, 1000);
    delay(500);
    Serial.println("----------Girl's Dormitory Alarm Activated----------");
  }
  else {
    noTone(buzzerPin);
    digitalWrite(ledPin, LOW);
    Serial.println("Alarm Deacticated");
  }
}

You need to edit your post and use code tags ( </> ) as the forum has a bad habit of changing code unless its formatted correctly.

This will print a message on the Serial console, so that's a form of "getting a message out".

And indeed please use code tags. It also makes code much more readable. But before doing so, do a CTRL-T in the IDE to get the indentation fixed. Helps a lot, too.

Thank you for your replies. I just edited the post.

This will print a message on the Serial console, so that's a form of "getting a message out".

@wvmarle Does that mean I don't have to make any changes to my coding?

Kalarm:
@wvmarle Does that mean I don't have to make any changes to my coding?

If what your code does what you want it to do, then no need to make changes. But that's up to you to decide.

Suppose you build your project and test it successfully and then one day, a few months later, you press the button and nothing happens.

Will that matter?

...R