const int temperaturePin = A3; // Connect the TMP36 sensor to analog pin A0
const int buzzerPin = 6; // Connect the piezo buzzer to digital pin 7
void setup() {
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Read the temperature from the TMP36 sensor
int sensorValue = analogRead(temperaturePin);
// Convert the sensor value to Celsius
float temperatureCelsius = (sensorValue / 1024.0) * 500;
// Check if the temperature exceeds a predefined threshold (e.g., 30 degrees Celsius)
if (temperatureCelsius > 500.0) {
// If the threshold is exceeded, sound the piezo buzzer
tone(buzzerPin, 1000); // You can change the frequency (in Hertz) as needed
delay(1000); // Sound the piezo buzzer for 1 second
noTone(buzzerPin); // Turn off the piezo buzzer
}
// Print the temperature value to the serial monitor
Serial.print("Temperature: ");
Serial.print(temperatureCelsius);
Serial.println(" °C");
// Delay for a moment before taking the next reading
delay(1000);
}