const int potPin = A0; // Analog input pin for the potentiometer
const int buzzerPin = 8; // Digital output pin for the buzzer
int previousValue = 0; // Variable to store the previous sensor value
int threshold = 500; // Threshold value for activating the buzzer
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(buzzerPin, OUTPUT); // Set the buzzer pin as an output
}
void loop() {
int sensorValue = analogRead(potPin); // Read analog value from potentiometer
if (sensorValue > threshold && previousValue <= threshold) { // Check if sensor value passes threshold
Serial.println("Alert: Health issue detected"); // Print alert message
tone(buzzerPin, 1000); // Activate the buzzer with a frequency of 1000 Hz
delay(200); // Buzz for 200 milliseconds
noTone(buzzerPin); // Turn off the buzzer
}
previousValue = sensorValue; // Update previous sensor value
delay(100); // Add a short delay to avoid flooding the serial monitor
}