Gyro Fluctuates Too Much While Motor is Running

I'm using an MPU9250 that is calibrated. I am currently only caring about the Yaw value as it is attached to a car and therefore pitch and roll do not matter. Without the car, running it on a simple arduino uno and a breadboard with VCC GND SCL and SDA hooked up gives consistent results like the one shown below:

280.78
279.68
279.37
278.95
279.55
278.41
277.92
277.91
277.03
277.17
277.17
277.73
277.71
277.79
276.97

However, when the car's motors are running, the values fluctuate by around 40 degrees:

110.80
116.87
129.03
137.35
150.86
152.86
160.36
140.51
143.01
144.81
145.21
156.14
136.32
142.53

I'm pretty sure it is the magnets in the motor causing this interference. However, the nearby 6-pack of AA batteries or the upload cable it's attached to might also be the problem. Either way, how would I filter out this noise from the motor or the batteries or wherever it's coming from? I thought of aluminum foil but I want to see if software-wise I can fix it first.

P.S The library I'm using as well as my calibration process can be found here
and the library can be found here
The original post that led me here is this

Thanks in advance,
Ian

No chance of a software fix and aluminum foil is useless. You have the classic case of the RFI (Radio Frequency Interference) from a motor.

This can be tackled in two ways.

  1. Reduce the RFI being generated from the motor.
  2. Reduce the RFI being picked up by the Arduino.

Both of which will involve decoupling techniques. Read about them here:-

How would I do either of the 2 solutions?
for example, would slowing the rpm of the motor make RFI less? is there a way to shield the Arduino?

I suggest to read the tutorial linked in post #2 above.

No.
If anything slowing down the motor with PWM would make it worse.

By adding supply decoupling on your parts. And making sure you have a reverse biased diode across a motor moving in only one direction.

If a motor can move in either direction by using a H-bridge then you need to use four diodes across your motor like this-:

The two switches represent your H-Bridge.
This is in addition to your capacitors and inductors as described in the tutorial.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.