const int temperaturePin = A0;
const int buzzerPin = 9;
const int ledPin = 10;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set pin modes
pinMode(temperaturePin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read analog value from temperature sensor
int analogValue = analogRead(temperaturePin);
// Calculate temperature in Celsius
float temperatureC = 1 / (log(1 / (1023.0 / analogValue - 1)) / 3950 + 1.0 / 298.15) - 273.15;
// Print temperature to serial monitor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println("°C");
// Activate the buzzer if temperature is greater than or equal to 38°C
if (temperatureC >= 38) {
tone(buzzerPin, 1000);
} else {
noTone(buzzerPin);
}
// Map analog value to LED brightness
int ledBrightness = map(analogValue, 953, 115, 0, 255);
// Set LED brightness based on temperature
analogWrite(ledPin, ledBrightness);
// Delay for one second before looping again
delay(1000);
}