Wiring for 2 MPU6050s and an Arduino Uno?

Hi!

I currently have one MPU 6050 connected to my arduino:

VCC -> 3.3V
GND -> GND
SCL -> A5
SDA -> A4
AD0 -> GND
INT -> D2

I'm able to get data from this. However, I'm trying to connect another MPU 6050 and I'm very confused on the wiring for this.

Later I will need to connect 4 total, but I think I need to buy some multiflexor thing, I'm not sure.
But I'm wondering if it's possible to experiment with at least 2 sensors atm connecting to the arudino.

I've found this video as a resource:

But I don't understand their wiring diagram...I don't get how I'm able to connect two wires to 3.3v, A5 and A4....

So if you have info on wiring, and additionally any info about attaching more to the arduino, please explain!

If you want to operate 4 sensors simultaneously (sequentially one after another), use a 74LS139 (2 to 4) decoder and connect its outputs with the AD0 pins of the GY-521 breakout boards of the MPU6050 sensors. The I2C addresses for the sensors will still remain the same 0x68 or 0x69. Assume that PB0 and PB1 lines of UNO are driving the decoder; the following codes (untested) will select Sensor-0 for data exchange:

pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
do
{
   Wire.beginTransmission(0x76);
   byte busStatus = Wire.endTransmission()
}
while(busStatus  != 0x00);
Serial.println(busStatus, DEC);   //0 means Sensor-0 is present!

BTW: Connect the Vcc-pin of the GY-521 breakout board of MPU6050 with 5V of UNO; The GY-521 breakout board of MPU6050 Sensor has a 5V/3.3V regulator.

Figure-1: GY-521 breakout board containing MPU-6050 sensor and 5V/3.3V Regulator.

Remember that 10cm is considered to be a long distance for an I2C bus. If you have more than that amout of TOTAL wire in the bus you may start to see problems.

Lots of people get 100cm on their I2C but it is not reliable once it leaves the workbench.

I'm sorry to say, but that video is not correct.
The MPU-6050 is a 3.3V chip. It is not allowed to connect 5V or a digital output pin from a 5V Arduino board to the AD0 pin of the MPU-6050.
The code with that video is also not correct, there is a "while(Wire.available() < 6) ;" in the code, meaning that the author does not fully understand the Arduino Wire library.

Could you use a 3.3V Arduino board ?
Then you can use a trick without extra hardware: Arduino Playground - MPU-6050.

With the Arduino Uno, you can try a I2C multiplexer. Those multiplexers will also do level shifting of the I2C bus signals between the 5V Arduino board and the 3.3V sensor: TCA9548A I2C Multiplexer : ID 2717 : $6.95 : Adafruit Industries, Unique & fun DIY electronics and kits

Koepel:
Could you use a 3.3V Arduino board ?
Then you can use a trick without extra hardware: Arduino Playground - HomePage.

With the Arduino Uno, you can try a I2C multiplexer. Those multiplexers will also do level shifting of the I2C bus signals between the 5V Arduino board and the 3.3V sensor: TCA9548A I2C Multiplexer : ID 2717 : $6.95 : Adafruit Industries, Unique & fun DIY electronics and kits

Hi, I was looking at the trick that's mentioned. So if I buy a shift register then I can connect multiple sensors to the board.

Is the wiring for all of the sensors the same?

Using more than two MPU-6050 sensors can be achieved by connecting each of the AD0 pins to a separate output of the Arduino

What's considered an output pin?
Right now my one is connected as I mentioned above:
VCC -> 3.3V
GND -> GND
SCL -> A5
SDA -> A4
AD0 -> GND
INT -> D2

What needs to change??
Also I'd love to at least connect two right now straight to my arduino....do you know how I do the wiring for that?

For just two, wire one of the AD0 pins to GND and the other to 3.3V.

But since you know you will need more than two, wire each MPU's AD0 pin to an Arduino pin and drive that pin as follows:

void setup() {
  //set the MPU pins to pullups, so the weak pullup in the Arduino tries to drag the pin up to 5V
  //but the internal protection diodes in the MPU won't let it go above 3.9V
  //so there will be a few micro-amps flowing into the MPU at all times

  pinMode(MPU1_AD0_Pin, INPUT_PULLUP);  
  pinMode(MPU2_AD0_Pin, INPUT_PULLUP);  
  pinMode(MPU3_AD0_Pin, INPUT_PULLUP);  

  ...
}

void loop() {
  digitalWrite(MPU1_AD0_Pin, LOW); //do this first, before making the pin an output
  pinMode(MPU1_AD0_Pin, OUTPUT); //now the pin is LOW

  //access the first MPU using address 0x68

  pinMode(MPU1_AD)_Pin, INPUT_PULLUP);  //deactivate MPU #1

  ...

Of course it would be better to put all of that activate/deactivate stuff into a function so you don't have to type all of that into the loop(). Maybe even use arrays to hold the pin numbers.

Can you give a link to where you bought your MPU-6050 module ? Some modules are 5V and 3.3V compatible, some have only a voltage regulator and some have wrong pullup resistors, many have a wrong capacitor making it extra noisy... and so on.

Just two right now: I prefer level shifters for SDA and SCL. Connect one AD0 to GND and connect the AD0 of the other module to 3.3V. There might be some kind of copper jumpers for AD0 on the module. Run a I2C Scanner and it should find 0x68 and 0x69.

To use four with a trick and a 5V Arduino board: Use two level shifters for SDA and SCL to create a 3.3V I2C bus. Connect that 3.3V I2C bus to all the sensors. Use four level shifters for four digital outputs to the AD0 of each module.

@MorganS, it is not allowed to connect a digital output of the 5V Arduino board to the AD0 pin of the 3.3V sensor.

Look closely. The digital OUTPUT is only ever LOW when it's connected to the MPU. Another "trick".

Only recommended for testing on the workbench and once you pick it up off the workbench, your warranty is voided.

MorganS:
Look closely. The digital OUTPUT is only ever LOW when it's connected to the MPU. Another "trick".

Only recommended for testing on the workbench and once you pick it up off the workbench, your warranty is voided.

You assume that the internet pullup resistor of the Arduino will not lift the voltage of the sensor ? When also the SDA and SCL are used that way, the MPU-6050 sensor might be one unhappy piggy, with so many things pulling at its legs.

Koepel:
Can you give a link to where you bought your MPU-6050 module ? Some modules are 5V and 3.3V compatible, some have only a voltage regulator and some have wrong pullup resistors, many have a wrong capacitor making it extra noisy... and so on.

https://www.amazon.com/MPU-6050-MPU6050-Accelerometer-Gyroscope-Converter/dp/B008BOPN40/ref=sr_1_2?ie=UTF8&qid=1530215075&sr=8-2&keywords=gyro+sensor

I'm not able to test out what you guys have said right now but when I get home I will read through these more thoroughly and update you all.

That one has a voltage regulator to make 3.3V for the sensor. I suggest to connect VCC to Arduino 5V pin and let the voltage regulator make 3.3V.
The pullup resistors for SDA and SCL are 2k2 to 3.3V. The 2k2 is low, but that makes it also safer when you connect the SDA and SCL directly to A4 and A5 of the Arduino Uno.

You need only one pair of those 2k2 pullup resistors. When connecting more modules to the I2C bus, I suggest to remove those 2k2 pullup resistors. If you connect one module to the Arduino Uno, and that module has the 2k2 resistors removed, then the MPU-6050 might get damaged.

That leaves the AD0 pin. With two sensors you can try to connect one to GND and the AD0 of another module to the Arduino 3.3V. With four sensors, you could try the selection code by MorganS, even if I think that it would turn the MPU-6050 into one unhappy piggy.

Seriously, when you buy a 3.3V Arduino board and better modules (for example with the MPU-9250), then you avoid almost all these problems and all this discussion and posts and opinions is no longer needed.

Hi. I'm so new to wiring generally and Arduino and everything.
So to make it really simplistic:

Before I was not using a breadboard, now I will be instead of connecting directly to my Arduino, so that a pin can connect to two wires, each connected to one of the two mpu6050s.

So Wiring:
MPU 1 -> Arduino/breadboard:
VCC -> 5V
GND -> GND
SCL -> A5
SDA -> A4
AD0 -> GND
INT -> D2

MPU 2 -> Arduino/breadboard:
VCC -> 5V
GND -> GND
SCL -> A5
SDA -> A4
AD0 -> 3.3V
INT -> D2

And can I still use the previously suggested code?

void setup() {
  //set the MPU pins to pullups, so the weak pullup in the Arduino tries to drag the pin up to 5V
  //but the internal protection diodes in the MPU won't let it go above 3.9V
  //so there will be a few micro-amps flowing into the MPU at all times

  pinMode(MPU1_AD0_Pin, INPUT_PULLUP);  
  pinMode(MPU2_AD0_Pin, INPUT_PULLUP);  

  ...
}

void loop() {
  digitalWrite(MPU1_AD0_Pin, LOW); //do this first, before making the pin an output
  pinMode(MPU1_AD0_Pin, OUTPUT); //now the pin is LOW

  //access the first MPU using address 0x68

  pinMode(MPU1_AD)_Pin, INPUT_PULLUP);  //deactivate MPU #1

  ...

And what I need to buy:
4 level shifters?

If your MPU board has a 5V pin then it is likely to have the level converters too.

Can you show us exactly what you have?

Koepel:
That one has a voltage regulator to make 3.3V for the sensor. I suggest to connect VCC to Arduino 5V pin and let the voltage regulator make 3.3V.

That leaves the AD0 pin. With two sensors you can try to connect one to GND and the AD0 of another module to the Arduino 3.3V. With four sensors, you could try the selection code by MorganS, even if I think that it would turn the MPU-6050 into one unhappy piggy.

Seriously, when you buy a 3.3V Arduino board and better modules (for example with the MPU-9250), then you avoid almost all these problems and all this discussion and posts and opinions is no longer needed.

GY-521 Breakout Board (Module) contains MPU6050 Sensor. I have experience working with this breakout board. The bpard works fine with its pin connected as follows with the UNO--
Vcc ---> 5V
AD0-pin (0V or 5V)
SDA/SCL ----. SDA/SCL

That indicates that the SDA/SCL/AD0 lines are 5V tolerant ike the HC-05 whose TXD-line is 5V tolerant and not the RXD-line.

To operate multiple GY-521 Breakout Boards sequentially, we can safely use 74LS138 type decoder to get the active signals for the AD0-pins of the sensor boards.

Hi.

Things are still not clear for me.

Here's my current connections:
So Wiring:
MPU 1 -> Arduino/breadboard:
VCC -> 5V
GND -> GND
SCL -> A5
SDA -> A4
AD0 -> GND
INT -> D2

MPU 2 -> Arduino/breadboard:
VCC -> 5V
GND -> GND
SCL -> A5
SDA -> A4
AD0 -> 3.3V
INT -> D2

I've attached the code I'm using.
It says that the connections failed....With other code I've been able to get the connections for 1.
But I really don't understand what I'm doing wrong, I can't even connect two MPU6050s to a single arduino.

Please give clear and simplistic advice, as I'm very new to this.

ex5.ino (11.5 KB)

If you are using the following breakout board, then the following connections are supposed to work. If you are using the raw sensor (MPU-6050), you have to follow all the rules of 3.3V logic.

Vcc pin of breakout board ---------------> UNO 5V
GND " ---------------> UNO GND
SDA/SCL " ---------------> UNO SDA/SCL
AD0 " ---------------> UNO GND if deviceAddess is 0x68; otherwise at 5V for deviceAddress 0x69


Figure-1: GY-521 breakout board containing MPU-6050 sensor and 5V/3.3V Regulator.

Ok, and that is supposed to work for wiring for both sensors?
I will try that now, and use the code I posted in the previous post.

What is OK?

Are you using the breakout board? Yes/No?

Are using the raw MPU-6050 sensor on the breadboard? Yes/No?