/**
Basic NTC Thermistor demo
https://wokwi.com/arduino/projects/299330254810382858
Assumes a 10K@25℃ NTC thermistor connected in series with a 10K resistor.
Copyright (C) 2021, Uri Shaked
*/
#include "thingProperties.h"
int milisec=2000;
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
void setup() {
Serial.begin(9600);
analogReadResolution(10);
pinMode(34,INPUT);//temp
pinMode(14,OUTPUT);//led
pinMode(12, OUTPUT);//buzzer
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
int analogValue = analogRead(34);
if (isnan(analogValue) ){
Serial.println(F("Failed to read from sensor!"));
return;
}
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
temperature = celsius;
if(celsius>=60){
digitalWrite(14, HIGH);
tone(12, 500);
delay(1000);
tone(12, 800);
delay(1000);
}
else{
digitalWrite(14, LOW);
tone(12, 0);
}
delay(1000);
}
/*
Since LEDOutput is READ_WRITE variable, onLEDOutputChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLEDOutputChange() {
// Add your code here to act upon LEDOutput change
if (lED_output == 1)
{
digitalWrite(2,HIGH);
}
else{
digitalWrite(2,LOW);
}
}
/*
Since SamplingStepVariable is READ_WRITE variable, onSamplingStepVariableChange() is
executed every time a new value is received from IoT Cloud.
*/
void onSamplingStepVariableChange() {
// Add your code here to act upon SamplingStepVariable change
//milisec=sampling_step_variable;
Serial.println("onSamplingStepVariableChange triggerd");
}