const int sensorPin = A0; const float baselineTemp = 25.0; const int buzzerPin = 8; void setup() { Serial.begin(9600); // open a serial port for(int pinNumber = 2; pinNumber < 5; pinNumber++){ pinMode(pinNumber, OUTPUT); digitalWrite(pinNumber, LOW); } pinMode(buzzerPin, OUTPUT); } void loop() { int sensorVal = analogRead(sensorPin); Serial.print("Sensor Value: "); Serial.print(sensorVal); // convert the ADC reading to voltage float voltage = (sensorVal/1024.0) * 5.0; Serial.print(", Volts: "); Serial.print(voltage); Serial.print(" , degrees C: "); // convert the voltage to temperature in degrees float temperature = (voltage - 0.5) * 100; Serial.print(temperature); String tempStatus = ""; //cold if(temperature < baselineTemp) { // if temp is less than 25 C, turn the blue LED on digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, LOW); tempStatus = "COLD :("; digitalWrite(buzzerPin, HIGH); tone(buzzerPin, 1024, 3000); } //getting cold else if(temperature >= baselineTemp && temperature < baselineTemp + 3){ // if temp is 27 C to 29 C, turn the yellow LED on digitalWrite(2, LOW); digitalWrite(3, HIGH); digitalWrite(4, LOW); tempStatus = "Still WARM but GETTING COLD!"; digitalWrite(buzzerPin, HIGH); tone(buzzerPin, 1024, 1000); } //hot else if(temperature >= baselineTemp + 3 && temperature < baselineTemp + 8){ // if temp is greater than 29 C, turn the red LED on digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, HIGH); tempStatus = "Still HOT :)"; } //no cup yet else{ digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); tempStatus = "Missing subject"; } Serial.println(" , Status: " + tempStatus); delay(3000); }