Hi, I'm kind of noob with Arduino and programming with C overall(new here too so sorry if this isn't in the right place), and been trying to figure out how to make the code print value, temperature to be more specific, when it changes like a 1 or half a Celsius up or down. When I just use the not equal != it prints it way too fast because the thermistor is too specific I think so it constantly changes a bit.
void loop() {
float TempF;
float Temp;
double newTemp = Thermistor(analogRead(ThermistorPIN));
Temp=Thermistor(analogRead(ThermistorPIN)); // read ADC and convert it to Celsius
TempF=ThermistorF(analogRead(ThermistorPIN)); // read ADC and convert it to Celsius
if(Temp != newTemp){
Temp = newTemp;
Serial.print(Temp,1); // display Celsius
Serial.print(" ");
Serial.println(TempF,1);
//delay(2000);
}
}
With this being the problem
if(Temp != newTemp)
So it reads Celsius and Fahrenheit correctly, but just saying it should print when value changes is too fast. I've tried to look at the Boolean operators but couldn't get to work, it doesn't give any errors though. I could just put the delay to it but would like to do it a bit differently
Depper:
Hi, I'm kind of noob with Arduino and programming with C overall(new here too so sorry if this isn't in the right place), and been trying to figure out how to make the code print value, temperature to be more specific, when it changes like a 1 or half a Celsius up or down. When I just use the not equal != it prints it way too fast because the thermistor is too specific I think so it constantly changes a bit.
void loop() {
float TempF;
float Temp;
double newTemp = Thermistor(analogRead(ThermistorPIN));
Temp=Thermistor(analogRead(ThermistorPIN)); // read ADC and convert it to Celsius
TempF=ThermistorF(analogRead(ThermistorPIN)); // read ADC and convert it to Celsius
if(Temp != newTemp){
Temp = newTemp;
Serial.print(Temp,1); // display Celsius
Serial.print(" ");
Serial.println(TempF,1);
//delay(2000);
}
}
With this being the problem
if(Temp != newTemp)
So it reads Celsius and Fahrenheit correctly, but just saying it should print when value changes is too fast. I've tried to look at the Boolean operators but couldn't get to work, it doesn't give any errors though. I could just put the delay to it but would like to do it a bit differently
You are just taking three consecutive readings.
And then you are testing for a change between consecutive readings.
You are not comparing the "previous loop value" to the "current loop value".
This ...
Temp = newTemp;
does nothing because you over-write BOTH variables with new values at the beginning of the loop.