

ARDUINO PIEZO SENSOR CODE CODE
👉️Executing the loop() function repeatedly, which contains the main code and: RawValue = digitalRead(ButtonPin) if (RawValue = 1)
ARDUINO PIEZO SENSOR CODE SERIAL
👉️ Prints a text message to the Serial Monitor indicating that the program has started. 👉️Initializes the Serial Monitor with a communication speed of 9, 600 baud. The voltage is 1 if you press the pushbutton and 0 if not. 👉️ Sets the Arduino pin connected to the pushbutton as an input pin, so the voltage can be read into the 10k resistor (kilo-ohm). 👉️ 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. 👉️Calling the setup() function, which initializes the program and: pinMode(SoundPin, INPUT) Otherwise, the value is true, so the alarm is tampered with and a sound detected.

If the value is false, the alarm was not triggered. 👉️Assigning the ButtonPin variable to pin 7 on the Arduino that is used to read the button status. 👉️Initializing to 300 the variable BuzzerFreq, which reflects the tone frequency of the buzzer. 👉️Assigning to pin 9 on the Arduino the BuzzerPin variable, which represents the positive terminal of the buzzer. 👉️The Sensitivity variable is initialized to 2 and has the minimum number of times a sound has to be detected to trigger an alarm. The SoundCount variable starts to 0, which contains the number of times the sound detector has detected a sound. 👉️Assigning to pin 8 on the Arduino the SoundPin variable, which represents the output pin on the sound detector. 👉️The RawValue variable that contains the data from the sound sensor is initialized to 0. Program int 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() Connect the other pin on the 3.3-V pin on the Arduino pushbutton.Connect the other end of the resistor with the Arduino GND pin. Connect a pin on the push button to a node with a resistor and a pin 7 wire on the Arduino.Connect the positive terminal to the Arduino pin 9 of the piezo buzzer.Connect the piezo buzzer's negative terminal with the Arduino GND pin.Connect the OUT pin to the Arduino pin 8 on the sound detector.Connect the GND pin to the Arduino GND pin on the sound detector.Connect the VCC pin to the Arduino 3.3-V pin on the sound detector.
