I’m using the TMP36 temperature sensor embedded in a larger application, running on the SparkFun RedBoard (= Arduino Uno). My understanding is that the output voltage of the TMP36 varies as a continuous (i.e., analog) function of ambient temperature. As a result, I expect continuous values out (and the data sheet also suggests this should be true; it shows a continuous line across temperature/voltage values). This should remain true after converting from voltage to degrees C, as I’m doing like so: ```
degreesC = (voltage - 0.5) * 100.0;
24.71 25.2 25.68 26.17 26.66 27.15 27.64 28.13 28.61 29.1 29.59
10 10 24 5 1 3 5 9 2 2 1
So not only am I getting discrete values, those values vary by nearly 5 degrees C within the course of a few seconds. So... something is not right, right?
The relevant code is as follows:
[before the setup]
float voltage = 0; //the voltage measured from the TMP36
float degreesC = 0; //the temperature in Celsius, calcuated from the voltage
[In the loop]
voltage = analogRead(A0) * 0.004882814; //convert the analog reading, which varies from 0 to 1023, back to a voltage value from 0-5 volts
degreesC = (voltage - 0.5) * 100.0; //convert the voltage to a temperature in degrees Celsius
Any ideas about how to fix this?