Giter VIP home page Giter VIP logo

smoothed's Introduction

Arduino IDE GitHub version GitHub Release Date GitHub download GitHub stars GitHub issues Codacy grade GitHub license

Smoothed

An Arduino library to store and smooth sensor inputs using various methods including:

  • a simple moving average of the last x sensor readings
  • a simple linear recursive exponential filter

Unlike many other smoothing/filtering libraries, Smoothed uses a template class to ensure sensor readings in any numerical data type can be handled. This makes it both lightweight and flexible.

How to Install

Smoothed can be installed from the Arduino IDE Library Manager. For more details on how to install libraries in the Arduino IDE, please see the Arduino website.

How to Use

A full example of using each smoothing method is provided with the library and can be found in the Arduino IDE under "File->Examples->Smoothed".

Firstly, you must include the library in your sketch:

#include <Smoothed.h>

Next, create an instance of the class defining what data type to use. The example below uses a type of float:

Smoothed <float> mySensor;

You can replace float with any numeric data type to suit your sensor readings and desired accuracy. See the included library example for a full list of supported data types.

Within the setup function, initialize the instance, defining the smoothing method and accuracy:

mySensor.begin(SMOOTHED_AVERAGE, 10);

In the above example we are using a simple average of the last 10 sensor readings.

And finally, write in a new sensor value and read the smoothed result:

// Read a sensor value from analogue pin 0
mySensor.add(analogRead(SENSOR_PIN));

// Output the smoothed sensor value to the serial
Serial.println(mySensor.get());

Planned Improvements/Changes

  1. Add a multi-sample method. Calls a passed function to obtain the sensor value x times and averages out.
  2. Add a Savitzky Golay filter.
  3. Add a running median filter. Best method to eliminate random spikes in an otherwise stable signal. Need to work out how to handle different data types. Rounding maybe??
  4. Publishing to the Arduino IDE Library list.

smoothed's People

Contributors

mattfryer avatar floesche avatar per1234 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.