const float BETA = 3950;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
analogReadResolution(10);
pinMode(25,INPUT);
}
void loop() {
if(Serial.available()>0){
String command = Serial.readStringUntil('\n');
if(command=="temp2"){
sensor_ntc();
}
}
delay(1000); // this speeds up the simulation
}
void sensor_ntc(){
int analogValue = analogRead(25);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
}