TMP36 provides discrete values and varies widely

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?

How long is the cable connecting the TMP36 to your RedBoard? A long cable can pickup noise that gets into the output and can skew your readings. Can you send a photo showing your connections?

Many thanks for your help. The cable isn’t terribly long; it was the one that came w the sparkfun inventor’s kit. Perhaps 5-6ft long.

Attached is an image.

As you see, I have an OpenLog attached as well, to capture data.

Here again, discrete temperature values that vary over a huge range (taken over approx 10 seconds):

17.87 18.36 19.34 19.82 20.31  20.8 21.29 21.78 22.27 22.75 23.24 24.22  25.2 
    2     8     3     7     3     4    10     7     5     6     5     2     3

Can you post more of your code? Also, can you provide either a pictures of the connections or a schematic? Finally, can you show examples of the sensor output including the raw ADC values, your calculated voltage, and your calculated temperature?

Also, the datasheet examples show the use of a decoupling capacitor.