Using a Buffer to Smooth Your Signals
Got an Arduino project that uses an analog sensor, but the readings keep jumping around? What you need is a moving average. This allows you to get a sense of the general change in your values over time, without being affected by random noise. It's good to use a moving average when you are measuring a continuous signal, such as:
- a Distance Sensor
- a stretch or flex sensor
- an accelerometer
The general idea of the moving average is to store the last n values, and every time a new value is recorded, average these out. These are stored in an array.
Ring Buffer
Example
In this example, we are measuring change on a knitted stretch sensor. A photo of the layout is shown on the left, and the circuit diagram for this layout (a )
seeing values using the serial plotter
Whenever you are dealing with an analog signal, it's always a good idea to take a look at the values you're getting first. It can be really helpful to see these plotted on a graph, rather than printed out, as this can give you a visual representation of how they change over time. For this we want to use the serial plotter. You can open this by clicking the 'graph' icon next to the
Consider this reading
Trade offs
The more values you use
