1

I am currently building a self balancing robot using an L298N motors driver,and MPU6050 using an arduino microcontroller.

I managed to control my motors movements with no issues. After I extracted the data from my MPU6050 which was easy by using MPU6050 library I faced a problem: When linking the motors movement according to MPU6050 readings, the sensor freezes and stops showing its data on the serial monitor after giving couple of readings, the motors keep moving. I even have capacitors soldered into my motors to filter the noise. I am definitely sure my sensor works perfectly because it was tested before implemented into the motors drivers circuit and code.

If anyone can give me any hints why does the MPU sensor stop giving readings please.

Thanks.

1
  • Did you ever get this resolved? I'm struggling with the same problem right now. I've tried pullup resistors which didn't fix things.
    – Glenn
    Commented Oct 8, 2017 at 18:59

2 Answers 2

1

The MPU6050 is an I2C device. By default the Arduino uses the internal pullup resistors in the IO pins for the pullups on the I2C bus.

This is bad - it makes the I2C bus very susceptible to noise, and motors are very noisy devices.

You need to make sure you have appropriate pullup resistors on the I2C bus (3.3KΩ is good) and keep the I2C wires as short as you reasonably can.

Also keeping power sources as separate as possible is essential. Don't be tempted to use the 5V power from the Arduino to power your motors - you must use an external power source, or the motors will cause havoc with the microcontroller circuitry and communications.

1
  • I am using a 12V battery to power my motors and the ground of the battery is linked to the ground of my motor driver then mounted onto the arduino. So you mean i must use 3.3K resistors and connect them to the SDA and SCL pins on the MPU6050??to prevent any oscillations affecting the sensor is that right ? Thanks
    – Salah
    Commented Sep 1, 2015 at 8:30
0

This answer addresses the additional questions in Salah's comment:

I am using a 12V battery to power my motors and the ground of the battery is linked to the ground of my motor driver then mounted onto the arduino. So you mean i must use 3.3K resistors and connect them to the SDA and SCL pins on the MPU6050??to prevent any oscillations affecting the sensor is that right ?

The MPU-6050 will work ok with Vdd = 3.3 V. More specifically, page 14 of the 1788002.pdf datasheet for MPU-6000/MPU-6050 products shows

VDD = 2.375V-3.46V, VLOGIC (MPU-6050 only) = 1.8V±5% or VDD, TA = 25°C

The wiring diagram on page 39 shows SDA and SCL being pulled up to VLOGIC (which is either 1.8 V or VDD, say 3.3 V).

One suitable choice would be to operate an 8 MHz Mega and the 6050 at 3.3 V and pull SDA and SCL up to 3.3 V via 3.3 KΩ resistors.

Another choice would be to operate a 16 MHz Mega at 5 V, operate the 6050 at 3.3 V, pull SDA and SCL up to 3.3 V via 3.3 KΩ resistors, and use 3.3V/5V level translations on SDA and SCL into the Mega.

Built-in pullups for I/O pins on Mega2560 and similar devices are spec'd at 20 KΩ min, 50 KΩ max, so will provide less restoring current when a device releases a pin, than will a 3.3 KΩ resistor, and thus may be less noise-resistant or operate less speedily.

The important issues for your power wiring are these:

1, Isolate the motor drive and logic drives. They can use the same ground point but motor current should not be running through the ground lead or leads that connect to the Arduino and the MPU-6050. And use decoupling capacitors as necessary.

2, Power the MPU-6050 with 3.3 V or less; pull up SDA and SCL to that level via 3.3 KΩ resistors; use level translators if the Mega operates at a different voltage than the MPU-6050.

Edit: About Grounding – For a detailed discussion, see Staying Well Grounded, an analog.com article. For overviews, see Star Grounding at lh-electric.net, or at wikipedia, Ground Noise, Ground Bounce, and Ground (electricity) Electronics. By “motor current should not be running through the ground lead or leads that connect to the Arduino and the MPU-6050” I refer to the use of separate wires for conducting ground current. Typically, this will matter only if your motor current is high or noisy. The idea is to have a heavy wire from the ground post of the battery to the motors, and a separate wire from the ground post of the battery to the Arduino and the MPU-6050. Voltage across a wire changes as current in the wire changes. Using separate ground wires, the Arduino and the MPU-6050 are less affected by ground wire voltage changes caused by motor current.

3
  • Thanks for your clarification,Which i will definitely try on this week just a little concern about "hey can use the same ground point but motor current should not be running through the ground lead or leads that connect to the Arduino and the MPU-6050. And use decoupling capacitors as necessary.".Do you mean my ground from the l298N driver should not be connected to arduino ??.If this is right how will the motors driver be grounded then ?Because my 12V input is connected to the motor driver from the battery and ground is connected to arduino
    – Salah
    Commented Sep 3, 2015 at 11:08
  • @Salah, see edit Commented Sep 3, 2015 at 15:19
  • Hi,Thanks for all the support guys ,Unfortunately i am still getting the same results in which the sensor still freezes and the motors continue working normally.I have added pull up resistors of 3.3k on SDA and SCL pins of the MPU6050 and still same results .I wonder if anyone has any other suggestions or if anyone knows any perfect Gyroscope sensor that i can use without facing such difficulties again .Help and support will be very much appreciated guys thanks
    – Salah
    Commented Sep 8, 2015 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.