Isolating X-Axis Readings from Accelerometer Interference

I am creating a project that will use the input from the x-axis accelerometer to control the output of LEDs. I have no problem reading the output from the x-axis, but I find that when I move my project in the y-axis, it affects the x-axis readings. My project needs to read the deceleration of the x-axis without any other interference. How do I isolate the x-axis reading?

Any help would be greatly appreciated.
file0.jpg
file1.jpg
Solution
A low pass filter smooths out rapid changes in data, so that will make x axis reading more stable U can using a formula: filteredValue = α * newReading + (1 - α) * oldFilteredValue
Where α (alpha) controls smoothing: lower α = more smoothing
U can add this code
const float alpha = 0.2;
float filteredX = 0;

// In loop:
filteredX = alpha * newX + (1 - alpha) * filteredX;

Adjust alpha (0.05 to 0.5) to balance between smoothness and responsiveness.

Try this and give me ur feedback
Was this page helpful?