I'm working on an Arduino robotics project that requires I find the position of 12 different angles (I'm making a walking scale model of the Star Wars AT-AT and need to measure the angle of three different parts of the four legs). I'm currently going to use GY-521 Gyroscope sensor, however, I need 12 (3 angles, 4 legs) and each sensor has the same I2C address. Any possible solution?

My knowledge of Arduino is moderate; knowledge of programming is basic/moderate; my knowledge of electronics is moderate/advanced.

Would you recommend using something else to find the position of the leg? ALL advice is welcome!!!

  • \$\begingroup\$ You can configure the module address of the module by pulling AD0 up or down. But it will only give you two different addresses. Leaving you with the need for 6 I2C channels. I doubt your Arduino has that many. Not sure why you need so many inertial sensors. You probably know the relative angles of the joints, so you can calculate everything from a single set of inertial sensors. \$\endgroup\$ – Eugene Sh. Nov 19 '19 at 22:13
  • \$\begingroup\$ Possible duplicate/related: electronics.stackexchange.com/q/130235/2028 \$\endgroup\$ – JYelton Nov 19 '19 at 22:21
  • \$\begingroup\$ First, gyros do not measure angles. Acceleromaters and inverse tangent math might, but not very well in motion. Likely what you really want are encoder, possibly in crude form rotary potentiometers. If you want to play with the GY-521's then by manipulating the AD0 pin to "select" only one to the I2C address that will be in use, you can use several without needing a multiplexor. \$\endgroup\$ – Chris Stratton Nov 20 '19 at 5:37

Let's try removing some XY-problem aspects first.

The basic goal is to find angles of 2-joint system. This can be done with GY-521 breakout boards, however there are many cons in this solution.

First, you cannot measure angle with gyroscope. For stationary system it can be done with accelerometers, but for mobile system you need a fusion of the gyro and accelerometer data.

Second, while MPU6050 has built-in DMP, making it work is a pain. Many hobbyists usually give up and implement fusion in software. This is not hard, but considering the amount of sensors it will be quite a draw on CPU and memory requirements. If you go this way, I would recommend getting breakout boards based on BNO055 sensor, which has nice fusion DMP that is much easier to use.

Third, unless you guarantee your model will be used on flat level surface only, you also would need additional MPU on the body itself, and then quite a lot of math to make sense of all of it.

All these troubles can be avoided by installing simple rotary pots in the joints and then reading them with ADC. If you have enough analog inputs on your Arduino this would be all you need. Otherwise you can multiplex feedback channels via MCU-controlled analog switch, like ADG731 to a single analog input.

Finally, if you planning on using your model on uneven or non-level surface, I'd recommend adding one MPU in the body and load sensors in the "feet". With some (much simple than above) math you should be able to control leg movements with enough precision to scale minor obstacles.


The modules have selectable address so two modules can be connected per bus segment. Split the single bus into multiple isolated segments for example with a 8 channel multiplexer.

  • \$\begingroup\$ Two modules? Nope, as many as you want at lest up to electrical/time limits. Just use the address select line as a chip select. \$\endgroup\$ – Chris Stratton Nov 20 '19 at 5:38
  • \$\begingroup\$ Yes that will work if AD0 pin changes the I2C address directly, like some chips do. But it won't if AD0 pin is sampled only during power on reset, like some chips do. \$\endgroup\$ – Justme Nov 20 '19 at 6:42

You can use an I2C multiplexer to select which I2C network to communicate with, for example https://learn.adafruit.com/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout with 8 outputs. This allows using 8 devices that all have the same I2C address, giving you 16 in this case where each sensor can be set to one out of two different addresses. There are basic driver libraries available online.

However, do you really want to use gyros? They will tell the rate of rotation, not the angle when immobile. An accelerometer would give you the static angle towards the ground but would be thrown off when the body part accelerates or slows down. It's common to combine the two for a full picture, but that takes some algorithms to do. Maybe you instead want to measure the angle of each joint?

Be careful if using I2C over larger distance than 10-20 cm as it is more prone to interference than other comm links.

  • \$\begingroup\$ Thank you! That's very helpful. I had taken a look at using the multiplexer, but wanted to make sure that is the best option before investing the capital. When you say measure the angle of each joint, could you specify what that would look like? \$\endgroup\$ – Seth Sullivan Nov 20 '19 at 2:06
  • \$\begingroup\$ The GY-521 modules are actually breakout boards for MPU6050 6-axis gyro + accelerometer chips, which can be used for measuring angles. \$\endgroup\$ – Maple Nov 20 '19 at 2:53
  • \$\begingroup\$ A mux is not needed, the AD0 pin can be used to switch the address of the chip, select only one at a time to the address addressed, while the others sitting at the alternate address will ignore traffic. But it's unclear that this sensor is suited to the task. \$\endgroup\$ – Chris Stratton Nov 20 '19 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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