Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Sound Alarm

The sound alarm is an essential device used to alert individuals about potential dangers or events. It is widely used in various applications, including home security systems, industrial safety systems, and emergency notification systems. In this article, we will explore the concept of a sound alarm and provide examples of Arduino-based projects that can be implemented.

Project: For this example project, we will create a simple sound alarm using an Arduino board. The objective is to trigger a loud sound whenever a specific event or condition occurs. The alarm will be activated by a push-button switch and can be deactivated by pressing the same button again.

Components List: To build this project, the following components are required:

  1. Arduino Uno - 1x
  2. Piezo Buzzer - 1x
  3. Push-Button Switch - 1x
  4. Jumper Wires - As required

Examples: Example 1: Simple Sound Alarm

// Pin Definitions
const int buzzerPin = 9;
const int buttonPin = 2;

// Variable to track button state
int buttonState = 0;

void setup() {
  // Set pin modes
  pinMode(buzzerPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  // Read the button state
  buttonState = digitalRead(buttonPin);

  // Check if the button is pressed
  if (buttonState == HIGH) {
    // Activate the sound alarm
    tone(buzzerPin, 1000);
    delay(1000);
    noTone(buzzerPin);
    delay(1000);
  }
}

Explanation:

  • We define the pin numbers for the buzzer and the push-button switch.
  • In the setup function, we set the pin modes for the buzzerPin as OUTPUT and buttonPin as INPUT.
  • In the loop function, we continuously check the state of the button using digitalRead.
  • If the button is pressed (buttonState == HIGH), we activate the sound alarm by generating a tone on the buzzerPin using the tone function. We then pause for a second (1000 milliseconds) before turning off the sound using the noTone function. Another second delay is added before repeating the process.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.