// Analog temperature sensor pin
const int analogPin = A2;
// Buzzer pin
const int buzzerPin = 3; // Change this to the digital pin to which your buzzer is connected
void setup() {
Serial.begin(115200);
pinMode(buzzerPin, OUTPUT); // Set the buzzer pin as an output
}
void loop() {
// Read the analog value from the temperature sensor
int sensorValue = analogRead(analogPin);
// Convert the analog value to temperature in degrees Celsius
float temperatureC = (sensorValue * 3.3 / 4095) * 10; // Assuming a 3.3V reference voltage
// Print the temperature to the serial monitor
Serial.print("Analog Value: ");
Serial.print(sensorValue);
Serial.print(", Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
// Check if the temperature exceeds a certain threshold (adjust as needed)
if (temperatureC > 25.0) {
// Play a tone on the buzzer
tone(buzzerPin, 1000,250); // You can adjust the frequency as needed
} else {
// Stop the tone on the buzzer
noTone(buzzerPin);
}
delay(1000); // Wait for a second before reading again
}