In this project, you'll create an advanced alarm system using an Arduino sound detector. The system will activate a buzzer when it detects a sound, such as breaking glass, kicked doors, voices, or other noises indicating someone's presence in the room. The alarm will continue to sound until the Reset button is pressed. Once reset, the system returns to its initial state, ready to detect new sounds. This versatile warning system enhances security by monitoring various types of disturbances.
Schematic Diagram1. **Sound Detector Connections:**
- Connect the VCC pin of the sound detector to the 3.3V pin on the Arduino.
- Connect the GND pin of the sound detector to the GND pin on the Arduino.
- Connect the OUT pin of the sound detector to pin 8 on the Arduino.
2. **Piezo Buzzer Connections:**
- Connect the negative terminal of the piezo buzzer to the GND pin on the Arduino.
- Connect the positive terminal of the piezo buzzer to pin 9 on the Arduino.
3. **Push Button Connections:**
- Connect one pin of the push button to a node with a resistor and a wire leading to pin 7 on the Arduino.
- Connect the other end of the resistor to the GND pin on the Arduino.
- Connect the other pin of the push button to the 3.3V pin on the Arduino.
Programint RawValue = 0;
int SoundPin = 8;
int SoundCount = 0;
int Sensitivity = 2;
int BuzzerPin = 9;
int BuzzerFreq = 300;
int ButtonPin = 7;
boolean AlarmTripped = false;
void setup()
{
pinMode(SoundPin, INPUT);
pinMode(ButtonPin, INPUT);
Serial.begin(9600);
Serial.println("Glass Break Alarm
...");
}
void loop()
{
RawValue = digitalRead(ButtonPin);
if (RawValue == 1)
{
// Reset alarm
AlarmTripped = false;
SoundCount = 0;
}
RawValue = digitalRead(SoundPin);
if (RawValue == 0)
{
Serial.print("SOUND DETECTED ...
SoundCount: ");
SoundCount++;
Serial.println(SoundCount);
if (SoundCount >= Sensitivity)
{
AlarmTripped = true;
}
}
if (AlarmTripped)
{
tone(BuzzerPin, BuzzerFreq);
}
else
{
noTone(BuzzerPin);
}
}
Program Analysisint RawValue = 0;
👉️The RawValue variable that contains the data from the sound sensor is initialized to 0.
int SoundPin = 8;
👉️Assigning to pin 8 on the Arduino the SoundPin variable, which represents the output pin on the sound detector.
int SoundCount = 0;
The SoundCount variable starts to 0, which contains the number of times the sound detector has detected a sound.
int Sensitivity = 2;
👉️The Sensitivity variable is initialized to 2 and has the minimum number of times a sound has to be detected to trigger an alarm.
int BuzzerPin = 9;
👉️Assigning to pin 9 on the Arduino the BuzzerPin variable, which represents the positive terminal of the buzzer.
int BuzzerFreq = 300;
👉️Initializing to 300 the variable BuzzerFreq, which reflects the tone frequency of the buzzer.
int ButtonPin = 7;
👉️Assigning the ButtonPin variable to pin 7 on the Arduino that is used to read the button status.
boolean AlarmTripped = false;
👉️Calling the variable AlarmTripped. If the value is false, the alarm was not triggered. Otherwise, the value is true, so the alarm is tampered with and a sound detected.
void setup()
👉️Calling the setup() function, which initializes the program and:
pinMode(SoundPin, INPUT);
👉️ Set the pin on the Arduino connected to the sound detector output pin to be an input pin to enable data to be read in from the sound detector.
pinMode(ButtonPin, INPUT);
👉️ Sets the Arduino pin connected to the pushbutton as an input pin, so the voltage can be read into the 10k resistor (kilo-ohm). The voltage is 1 if you press the pushbutton and 0 if not.
Serial.begin(9600);
👉️Initializes the Serial Monitor with a communication speed of 9, 600 baud.
Serial.println("Glass Break Alarm...");
👉️ Prints a text message to the Serial Monitor indicating that the program has started.
void loop()
👉️Executing the loop() function repeatedly, which contains the main code and:
RawValue = digitalRead(ButtonPin);
if (RawValue == 1)
👉️ Reads the status of the push button. If the push button has been pressed, the alarm is reset, and the number of sounds detected is set to 0.
AlarmTripped = false;
SoundCount = 0;
RawValue = digitalRead(SoundPin);
if (RawValue == 0)
Serial.print("SOUND DETECTED ...SoundCount: ");
👉️ Then prints a text message to the Serial Monitor indicating that a sound has been detected and the number of sounds that have been detected.
SoundCount++;
👉️ Determines the status of the sound detector. If the sound detector has detected a sound, then the number of sounds that have been counted is increased.
Serial.println(SoundCount);
if (SoundCount >= Sensitivity)
👉️ If the number of sounds that have been counted is equal to or greater than the sensitivity value, then sets the alarm to be tripped.
AlarmTripped = true;
if (AlarmTripped)
👉️If the alarm has been tripped, then produces a sound with the buzzer.
tone(BuzzerPin, BuzzerFreq);
👉️ If the alarm has not been tripped, then stops any sound from the buzzer that is being produced.
else
noTone(BuzzerPin);
Comments