float temp; //Temperature variable
int LED = 6; //Led digital pin
int buzzerPin = 7; //Buzzer digital pin
const float BETA = 3950; //Beta Coefficient of the thermistor
void setup() {
//Setup for the buzzer and the LED diode
pinMode(buzzerPin,OUTPUT);
pinMode(LED,OUTPUT);
Serial.begin(9600);
}
void loop() {
//Read the value from the A0 analog pin (pin that the NTC is connected to)
int analogValue = analogRead(A0);
//Convert the read value to Celsius degrees
//This formula has been taken from the official Wokwi documentation
float temp = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
//Print the current temperature
Serial.print("Temperatura: ");
Serial.print(temp);
Serial.println(" ℃");
delay(500);
//Perform the actions of turning on/off the LED and the buzzer, based on the given temperature
if (temp <= 40) {
Serial.print("Uključi tihi alarm.");
digitalWrite(LED, LOW);
tone(buzzerPin, 1000, 1000);
} else if (temp > 40 && temp <= 45) {
Serial.print("Uključi jaki alarm.");
digitalWrite(LED, LOW);
tone(buzzerPin, 2000, 1000);
} else if (temp > 45 && temp <= 50) {
Serial.print("Uključi crvenu diodu i jak zvučni alarm.");
digitalWrite(LED, HIGH);
tone(buzzerPin, 4000, 1000);
} else if(temp > 50) {
Serial.println("Ugasi uređaj.");
digitalWrite(LED, LOW);
digitalWrite(buzzerPin, LOW);
while (true);
}
delay(500);
Serial.print("\n-------------------------------------------\n");
}