user47611: how can I make multi master Arduino device to work with single I2C device? 
As both the master device are 20 m away from Slave device, 
I am using the I2C relay board to connect with 2 Arduino boards and need to connect I2C device and create the two way switching technique from this. 
Any suggestions here will be a great help.

user30198: The answers by Majenko and chrisl are far too optimistic in my opinion.
A distance of 20 meters is not possible. The I2C bus can be 20 cm or 50 cm.
There is no library that supports a multi-master bus for the Arduino Uno.
You have to change your project. Make one Arduino board the Master, and let the Master retrieve data from the other board and the Master writes to the relay board. You need a bus capable of such a distance or use wireless. The RS-485 bus has no problems with 20 meters. Adafruit has a number of RFM69 modules, those should have no problem with 20 meters.

There are chips that translate the I2C bus signals into differential signals that can be used with a twisted pair cable (for example a cheap Cat5 ethernet cable). The SparkFun Differential I2C Breakout makes it easy to put a I2C device at a longer distance.
(Thanks to @PimV for this addition).

user4143: What you want is to operate in multi-master mode.  This is a supported configuration of I2C - however the Arduino API has no support for it.
It involves each master identifying if a collision has occurred and stopping transmission if it has - to then retry transmission later on.
The Arduino hardware can do it, but the software can't. You would have to bypass the software and control the I2C interface yourself (or locate a better library than the Wire library that supports multi-master).

47611: <p>how can I make multi master Arduino device to work with single I2C device? 
As both the master device are 20 m away from Slave device, </p>

<p>I am using the <a href="https://store.ncd.io/product/8-channel-general-purpose-spdt-relay-controller-with-i2c-interface/" rel="nofollow noreferrer">I2C relay board</a> to connect with 2 Arduino boards and need to connect I2C device and create the two way switching technique from this. </p>

<p>Any suggestions here will be a great help.</p>
 30198: <p>The answers by Majenko and chrisl are far too optimistic in my opinion.</p>

<p>A distance of 20 meters is not possible. The I2C bus can be 20 cm or 50 cm.</p>

<p>There is no library that supports a multi-master bus for the Arduino Uno.</p>

<p>You have to change your project. Make one Arduino board the Master, and let the Master retrieve data from the other board and the Master writes to the relay board. You need a bus capable of such a distance or use wireless. The RS-485 bus has no problems with 20 meters. Adafruit has a number of RFM69 modules, those should have no problem with 20 meters.</p>

<hr>

<p>There are chips that translate the I2C bus signals into differential signals that can be used with a twisted pair cable (for example a cheap Cat5 ethernet cable). The <a href="https://www.sparkfun.com/products/14589" rel="nofollow noreferrer">SparkFun Differential I2C Breakout</a> makes it easy to put a I2C device at a longer distance.<br>
(<em>Thanks to @PimV for this addition</em>).</p>
 4143: <p>What you want is to operate in <em>multi-master</em> mode.  This is a supported configuration of I2C - however the Arduino API has no support for it.</p>

<p>It involves each master identifying if a collision has occurred and stopping transmission if it has - to then retry transmission later on.</p>

<p>The Arduino hardware can do it, but the software can't. You would have to bypass the software and control the I2C interface yourself (or locate a better library than the Wire library that supports multi-master).</p>
