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.
attachment 0
attachment 1
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;...
Jump to solution
7 Replies
aymen ammari
aymen ammari6mo ago
This is the code I'm working with #include <Arduino_LSM9DS1.h> // Include the library for the LSM9DS1 IMU void setup() { Serial.begin(9600); while (!Serial); // Initialize the IMU if (!IMU.begin()) { Serial.println("Failed to initialize IMU!"); while (1); } Serial.println("IMU initialized!"); } void loop() { float x, y, z; // Check if there is new acceleration data available if (IMU.accelerationAvailable()) { // Read the acceleration data IMU.readAcceleration(x, y, z); // Print the X-axis acceleration value Serial.print("X: "); Serial.println(x); } delay(500); // Delay for readability }
wafa_ath
wafa_ath6mo ago
Hey @aymen ammari , consider using a low pass filter to reduce noise and sudden movements.
aymen ammari
aymen ammari6mo ago
I want to eliminate Y axis is that Achievable? @wafa_ath
wafa_ath
wafa_ath6mo ago
you can apply a strong low pass filter on x axis , and ignore reading from y axis completely on ur code
aymen ammari
aymen ammari6mo ago
Can you explain more about low base filter and how I can apply it? Thank you
Solution
wafa_ath
wafa_ath6mo ago
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
aymen ammari
aymen ammari6mo ago
I'll try this real quick, thank you @wafa_ath
Want results from more Discord servers?
Add your server