I am building a self balancing robot. When my motor is not plugged in it returns the angle perfectly but once the motors are on then the MPU will go crazy before eventually setting off.
below is my circuit diagram, but the 9V batteries are actually AA's. and the Arduino is powered via usb cable at the moment.
I know this is EMI of some sort. To counter this I have attached my MPU 6050 directly to the Arduino, I put capacitors on the motors(as seen in the circuit diagram) and I have even put layers of tinfoil between my Arduino and motors/motor controller) and I moved them as far away as possible(approx. 12cm).
When I have 5 AA batteries for the motor it works well but my motors require 8 to operate at the speed I need and the when I use 8 the EMI comes and my robot will run for a second before the I2C communication fails.
Please give any suggestions you have, I am currently pulling my hair out.
Can you please post a circuit diagram, not a Fritzy.
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, component names and pin labels.
Can you post links to specs/data of your motors?
Can you please post image(s) of your project, so we can see your component layout?
Do you have a DMM?
Most likely the power supply is inadequate, or inadequately decoupled.
Fritzing diagrams are mostly useless and often very misleading, so please post a hand drawn wiring diagram, with all components and pins labeled. A photo of the setup would help, too.
Good job on the schematic. You are missing the pull up resistors for the I2C bus. Since the micro is at 5V 4.7K would work OK. With those resistors missing the noise may be helping you by putting charge on the I2C lines. This is not practical, repeatable or reliable. Add the resistors, they should swamp the noise out. Try putting a 100nf cap across the AAA batteries for high frequency bypass.
Hi again, do you mean I put the pull up resistors on the VCC or the SCL and SDA? and when I pull-up do I use the 5V line or 3.3V line? (My IMU is powered by 3.3v currently)
My reading also mentions something about disabling the Arduino's internal pull-ups, do you have any knowledge of that?
Nice catch on the voltage. You need two resistors about 1.3K each. Fasten one end of each resistor to +3V3 and the other ends 1 each to SCL and SDA. Normally you pull up to the processor voltage. There are many I2C devices that will work on 3V3 but tolerate 5V on the SCL and SDA pins.