Connecting Four MPU 6050 to Arduino Mega

Hey,
so I have a project where I need to connect four mpu6050 to arduino mega. I am a bit new to Arduino coding and mpu6050. But, I know that we can change the address of mpu6050 by making AD0 pin high or low i.e. (0×68) when low and (0×69) when high. So I get how we will be able to connect 2 MPU6050s but I can't seem to get how to connect 4. Btw I know we can use a multiplexer, but is there a way to make it work without using a multiplexer. I wanted to know how to connect them and also the code.

Thank you!

Yes, if you have a 3.3V Arduino board.

Using AD0 (with a 3.3V Arduino board):

Keep all sensors at 0x69 and never use that in software. Have all the AD0 pins connected to digital pins.
Bring one sensor to 0x68 by making its AD0 pin low. Then use that sensor. When finished make that AD0 high.
You can not do this with a Arduino Mega, because then you would push 5V into the AD0 pin. That will damage the sensor.

Using a software I2C library:

By using a software I2C library, it is possible to create multiple I2C buses. It is allowed the share the SCL pin for all the buses.
You only need one extra I2C bus, because you can already can set them at 0x68 and 0x69.
The libraries for the sensor might have to be changed (a little or a lot), to use the software I2C bus.

Warning:

The Arduino Mega 2560 board is the only board with 10k pullup resistors to 5V for the I2C bus. You should not connect those SDA and SCL directly to a 3.3V sensor chip. You need a I2C level shifter.
If you create an extra I2C bus with software, then I suggest to use a level shifter for that bus as well.

1 Like

Hey, thank you so much for the reply

So if we keep changing the AD0 from high to low wouldn't that affect the delay also the sensors wouldn't work simultaneously, they would work one after another right? Because, I want all four of them to work at the same time. Actually I want to mount them on four wheels of a vehicle (buggy).

Also if I use two on software I2C and two on the harware one, would they work on different timings or something?

You may not connect a pin from a Arduino Mega 2560 board directly to a pin of a 3.3V sensor !

Changing the AD0 to low only changes the I2C interface of the sensor. The accelerator and gyro keep working. There is no delay.

The software I2C is not much slower than hardware I2C. In some cases it is faster.

Suppose you have four sensors with four I2C addresses on the I2C bus. Then you have to use the Wire library to collect the data one by one. If you use AD0 to select a sensor or use a extra software I2C bus, then you still have to collect the data one by one. You won't even know the difference.

The Wire.endTransmission() and Wire.requestFrom() wait until the I2C session has finished. The Arduino Wire library uses a interrupt that handles most of the I2C functionality. But since it waits until the I2C session has finished, a software I2C library is almost as fast.

1 Like

Okay thanks a lot. I will try to write the code then using this method. I'll post the update here.

What are you going to do with that 5V Mega board ? Are you going to use level shifters, or do you have MPU-6050 modules with level shifters ? Also level shifter for AD0 ?

The Arduino mega that I have has a 3.3V pin.

No ! please do not connect a digital output directly to a pin of a 3.3V sensor.

When you do digitalWrite( pin, HIGH); then that pin outputs 5V up to 40mA. You may not push that into the AD0 pin of the 3.3V sensor.

Even connecting SDA and SCL from the Mega board directly to the sensor is not safe, since the Mega board has onboard pullup resistors of 10k to 5V.

You have to use level shifters for all the signals, or buy a 3.3V Arduino board.

I have always connected my MPU6050 (Fig-1) Module (5V supply, 3.3V logic) directly with UNO (5V supply, 5V logic) and found it working. AD0-pin responses well at 0V and 5V in respect of I2C address change.


Figure-1:

I have tried connecting one sensor and it didn't damage it.

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