#define R 4 // Red LED pin
#define Y 8 // Yellow LED pin
#define G 10 // Green LED pin
#define BUZZER 2 // Buzzer pin
#define TEMP_SENSOR A0 // Analog temperature sensor pin
const float BETA = 3950; // Beta Coefficient of the thermistor
void setup() {
pinMode(R, OUTPUT);
pinMode(Y, OUTPUT);
pinMode(G, OUTPUT);
pinMode(BUZZER, OUTPUT);
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int analogValue = analogRead(TEMP_SENSOR); // Read raw temperature sensor value
float resistance = 1023.0 / analogValue - 1.0; // Convert ADC to resistance ratio
resistance = 10000.0 / resistance; // Assuming a 10kOhm pull-up resistor
// Convert resistance to temperature (Celsius)
float celsius = 1 / (log(resistance / 10000.0) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Analog Value: ");
Serial.println(analogValue); // Debugging: print the raw sensor value
Serial.print("Temperature (°C): ");
Serial.println(celsius); // Debugging: print the temperature value
if (celsius < 5) {
// Temperature below 0°C
digitalWrite(Y, HIGH); // Yellow LED ON
digitalWrite(G, LOW); // Green LED OFF
digitalWrite(R, LOW); // Red LED OFF
tone(BUZZER, 200); // Sound the buzzer at 1kHz
}
else if (celsius >= 5 && celsius <= 15) {
// Temperature between 0°C and 25°C
digitalWrite(G, HIGH); // Green LED ON
digitalWrite(Y, LOW); // Yellow LED OFF
digitalWrite(R, LOW); // Red LED OFF
noTone(BUZZER); // Buzzer OFF
}
else if (celsius > 15) {
// Temperature above 25°C
digitalWrite(R, HIGH); // Red LED ON
digitalWrite(Y, LOW); // Yellow LED OFF
digitalWrite(G, LOW); // Green LED OFF
tone(BUZZER, 2000); // Sound the buzzer at 2kHz
}
delay(500); // Small delay to stabilize readings
}