I wrote a Arduino library to smoothen jitter in analog output signals. This can be very useful when used with potentiometers, temperature sensors or similar devices.
The analogReadSmooth() function averages consecutive output readings. You can define how many readings you want to average (window size). Choosing a large window size will smoothen the output considerably but will also slow down detection of actual signal changes. You need to adjust the window size according to your needs when instantiating the AnalogSmooth object.
Here a brief usage example:
#include <AnalogSmooth.h> int analogPin = 1; // Defaults to window size 10 AnalogSmooth as = AnalogSmooth(); // Window size can range from 1 - 100 AnalogSmooth as100 = AnalogSmooth(100); void setup() { Serial.begin(9600); } void loop() { // Regular reading float analog = analogRead(analogPin); Serial.print("Non-Smooth: "); Serial.println(analog); // Smoothing with window size 10 float analogSmooth = as.smooth(analog); Serial.print("Smooth (10): "); Serial.println(analogSmooth); // Smoothing with window size 100 float analogSmooth100 = as100.analogReadSmooth(analogPin); Serial.print("Smooth (100): "); Serial.println(analogSmooth100); Serial.println(""); delay(1000); }
The library can be downloaded on GitHub and then simply needs to be placed in the Arduino libray folder.