How to produce a constant angle reading? Accelerometers, gyros? Both?

Hi. I'm doing a university project and I'm trying to make a controller for an electric longboardboard that gives me the tilt angle of my board, basically I want the board to detect when the user starts going uphill, and from the angle of inclination, produce an output signal for a motor, so the steeper the hill the more power output. At the moment i'm only working with small 6V dc motors just to model the output visually. I have set up a really basic model which kind of works, it uses an ADXL335. As i tilt it a small motor starts to rotate, faster depending on the gradient.

The problem is, if applied to a real board, when pushing the longboard there are obviously large spikes in the output readings which give false hill gradients causing the motor to speed up. Does anyone have any suggestions of how I might filter these spikes out? It doesn't matter if there is a bit of a delay. I'm only concerned with one direction of movement, when the board is going forward, and for my project, if it was easier I could even use a single axis?

I'm thinking that I might possibly need an IMU instead of the accelerometer by itself? but even then it will still have similar problems without filtering? but may give a smoother more constant reading?

I am an amateur Arduino user (first time) so any help would be really appreciated!

Thanks!

Firstly you need to try substantial low-pass filtering, perhaps a cutoff frequency of 0.3Hz, and see if that's an improvement.

Beware of high amplitude mechanical oscillation and vibration - ultimately this will overload the sensor and prevent a LPF'd version from being faithful to reality - with significant high-frequency components the analog anti-aliasing filter will need to setup properly if you do your main LPF in the digital domain.

Gyros will certainly give much more accurate information on short timescales, and married with an accelerometer to provide drift-correction you can get good orientation information (except for yaw). So an IMU should definitely work well - if more expensive.

Thanks for getting back to me. Depending on the road surface, there could be heavy vibration at times which I can imagine being a problem anyway. Maybe for my prototype it wont be so much of a problem but for the final thing i'd look at something else. At least with a low pass filter I could use the components I already have.

Anti-vibration mounting will also help the electronics from falling apart of course :slight_smile: