How to smooth analog data?
It's likely that your input is simply quite noisy. Applying some form of averaging here is your best bet.

The simplest solution is to take n samples and average them together to produce a result. This divides your sampling rate by the number of samples you use per averaging interval.

Another option is to use a digital filter; the simplest to implement is a first-order infinite impulse response, and looks something like this:

accumulator = 0.9 * accumulator + input


Where input is the ADC reading. Each time you update the filter with a new reading, you're taking a weighted average of the new data and all the old data. To get the averaged result out, divide accumulator by the inverse of the weighting - in this case, 0.1, like so:

value = accumulator / (1 - 0.9)


The weighting value controls how much averaging you get, and how quickly results converge when there's a change to the input; in this case each value is 90% dependent on the previous state and only 10% dependent on the new reading.

If you pick weightings that are powers of 2 - eg, 1/2, 1/4, etc - you can execute this very efficiently on a microcontroller without needing expensive division operations. For instance, picking a weighting value of 1/16 (=6.25%), you can compute your accumulator like this:

accumulator = accumulator - (accumulator &gt;&gt; 4) + value


and get the result like this:

result = accumulator &gt;&gt; 4