Maker Pro
Maker Pro

How do I add up analogue inputs to average them?

Waynelee

Mar 22, 2021
4
Joined
Mar 22, 2021
Messages
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,799
Joined
Nov 17, 2011
Messages
13,799
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
Joined
Mar 22, 2021
Messages
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,799
Joined
Nov 17, 2011
Messages
13,799
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.
 

Bluejets

Oct 5, 2014
7,093
Joined
Oct 5, 2014
Messages
7,093
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.
 
Top