Finding and Polishing Edge Values

The physical world often is far from perfect. That’s especially true for the data many sensors emit, and accelerometers are no exception. They vary slightly in the minimum and maximum values they generate, and they often jitter. They might change their output values even though you haven’t moved them, or they might not change their output values correctly. In this section, we’ll determine the sensor’s minimum and maximum values, and we’ll flatten the jitter.

Finding the edge values of the sensor is easy, but it cannot be easily automated. You have to constantly read the sensor’s output while moving it. Here’s a program that does the job:

MotionSensor/SensorValues/SensorValues.ino
 
const​ ​unsigned​ ​int​ X_AXIS_PIN ...

Get Arduino: A Quick-Start Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.