How to smoothing average multuple Analog reads

First of all, i'll apologise for not showing my attempted code as i typed this on my mobile device.

I am reading multiple voltages from a DC source but the ADC values are a mess, jumping high and low.

I found the IDE Inbuilt "Smoothing" example and would like to implement it in my code.

My problem is i don't know how to port it into my current "multiple readings" code.

Hope i am clear enough to get help.

Thanks in advance.

sounds like a wiring issue if values are fluctuating significantly with a DC input

i read recently that there may be only one ADC that is switched between ports and when reading a different port the port should be read twice and the 1st reading ignored

First, do this:

rawvalue = analogRead(A0);
rawvalue = analogRead(A0);

The first read "preconditions" the ADC, and the second read will be much more accurate.
If that's not helping enough, put at the top of your code:

int rawvalue;
const int factor = 8;

and in the body of your code:

rawvalue = analogRead(A0);
rawvalue = analogRead(A0);
avgvalue = rawvalue/factor+(avgvalue*(factor-1))/(factor);

You can adjust the smoothing factor easily. YMMV, depending on the code you haven't shared.

1 Like

Then it's a hardware issue.
Trying to fix it in software will be a waste of time.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.