Login Join Maker Pro
Or sign in with

# How do I add up analogue inputs to average them?

#### Waynelee

Mar 22, 2021
4
Hey, there
I would like to read a sensor (acs712) a number of times (20), add them all up, then divide them by the number of reads. So I can get an average to give me a sort of analogue "debounce".
Am I guessing the sum function?

I sincerely appreciate any advice you can all give me, I'm incredibly excited about learning all of this!

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
13,461
I assume you want to do this using a microcontroller, right? What controller do you use?
You can do it your way, this will average packets of 20 values each. I.e. you will get one output for every 20 inputs.

Another approach is a moving average (or rolling average). This will give you an output for every input, also averaged over e.g. 20 values. The advantage is that this method will allow you to react faster to change in input, quickly detect trends etc.

#### Waynelee

Mar 22, 2021
4
I get an idea, having a A2D converter for the sensor, then 20 digital values that can be averaged by a MCU, CPU or GPU.

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
13,461
The ACS712 has a built-in filter. You can select the amount of noise suppression by changing the filter capacitor on pin 6. No need to average on the mcu, but possible, of course.
Which mcu will you use? many of today's mcus have built-in ADCs, so you wouldn't need a separate ADC, unless you want an accuracy much higher than what a built-in ADC of an mcu can offer.

#### Waynelee

Mar 22, 2021
4
TI MSP430G2452
ADC channels – 8
ADC Resolution – 10-Bit SAR

#### Bluejets

Oct 5, 2014
6,700
Arduino have 10 bit resolution on the adc and easy to use into the bargain.
If you are measuring dc, then then INA219 is a good alternative and on I2c.

C
Replies
29
Views
3K
Phil Allison
P
C
Replies
4
Views
1K
clubsprint
C
Replies
19
Views
300
Replies
4
Views
226
Replies
5
Views
2K