loading

Maybe sometimes we want to share the workload of one Arduino with another. Or maybe we want more digital or analog pins. Inter-Integrated Circuit or I2C (pronounced I squared C) is the best solution.

I2C is an interesting protocol. It's usually used to communicate between components on motherboards in cameras and in any embedded electronic system.

Here, we will make an I2C bus using two Arduinos. We will program one master Arduino to command the other slave Arduino to blink its built-in LED once or twice depending on the received value.

In order to build this we need the following "ingredients":

  • 2 Arduinos
  • Jumper cables
This instructable and many more can be found in my Arduino Development Cookbookavailable here. :D

Step 1: How to connect them

Follow these steps to connect two Arduino UNOs using I2C:

  1. Connect pins A4 and A5 on one Arduino to the same pins on the other one.
  2. The GND line has to be common for both Arduinos. Connect it with a jumper.

We also have a schematic and a "breadboard" implementation, both easy to follow. Luckily, it's a simple implementation.

Remember never to connect 5 V and 3.3 V Arduinos together. It won't
hurt the 5V Arduino, but it will certainly annoy its 3.3 V brother!
<p>helllo i am ussing these code and testing it using proteus but when i run proteus only one time data is received by slave, i have connected i2c terminal, thus can say master is properly sending the data</p>
<p>Hello!<br>I'm new to arduino and I want to start a project in which I will use a lot of vibration sensors that will change the color or turn ON/OFF the led strip or led lamp and maybe a buzzer !<br>The sensors with LEDs and the buzzer will be attached to panels that after being hit with with a ball the led will turn on or of or maybe change the color!<br><br>Can someone help with this project!<br>What arduino boards should I use, what kind of vibration sensors and so one!<br><br>Thank you very much!</p>
<p>Thanks a lot, it was really helpful for me!</p>
<p>I have connected a standard Arduino Uno with a RedBoard Uno precisely as shown. The Standard UNO is the slave and the RedBoard UNO is the master. Everything checks (numerous times) but after loading the sketches, after power up - nothing. Anybody have advice on what I left out? -Thanks</p>
<p>It would be nice to know if both boards' I2C ports are working. You can test this by connecting to any other I2C devices you may have lying around or else spend a few dollars to buy something like an I2C LCD panel on eBay.</p>
<p>If i want to do sensors in I2C, I see a lot of info that the sensors need to be &quot;I2C sensors&quot;. But is it possible to use a simple sensor like a photocell (or a LM35 temperature sensor) and put it into the slave arduino? If this is done, the slave has an address(the slave arduino address), so the &quot;address&quot; requirement is met; but if this wouldn't work, why not?</p>
<p>Here is a very good article where he did exactly that: http://www.techbitar.com/how-to-network-many-arduinos-with-sensors-using-i2c.html</p>
<p>Trying to download the PDF and I'm asked to login. I'm already logged in but unable to access the PDF. What's up with this??? </p>
<p>hello. im just learning how to use arduino. i got a question. how to connect multiple analog sensors to slave arduino uno. the master is also another arduino uno. i try it. but i only read one analog output from slave. but i want more then that. can anyone tell me how??? by the way, im using i2c and wire.h method. thanks.</p>
<p>Hi, I have set this up and it works very well transferring data from the Master to the Slave and Serial Printing it.</p><p>But, I want to 'print' it to a TFT and this does not work.</p><p>My sketch for the slave writes header text to the TFT and then should write text sent from the master.</p><p>The header writes OK, however, as soon as the wire.onReceive event is triggered the TFT screen goes blank.</p><p>Anyone know why this may be?</p><p>Bill</p>
<p>Hi Cornel,</p><p>First of all thank you very much for explaining the I2C concept using Arduino in a simple and straight forward way. I used your example and it worked like a charm (but after replacing old methods with read() and write() in new version of Arduino). </p><p>You helped me to generate interest in using the i2C communication than USART, where I struggled lots of to get the right values and not the garbled data. </p><p>However, I have a question, in my case, if master also has to receive response from the slave after they performed the action- let's called it acknowledgement. Could you pls provide your an expert advice how to achieve this? In other words, how to achieve bidirectional communication by Master and Slave ? </p><p>Currently, in UART, we can achive this by using both Tx &amp; Rx at the same time.</p><p>Once again thanks for your support and publishing this topic here.</p><p>Regards,</p><p>Pradip</p>
<p>Hi Pradip,</p><p>Just implement the according protocol. You can send data to the slave and you can read data. So send a command to provide the data at a certain address. Eventually you need to instruct the slave to provide byte after byte.</p>
<p>Hi,</p><p>I dunno any one asked before,so I asked again.</p><p>How to make Slave to Sent data to Master Arduino??</p>
Hi,<br><br>The Slave cannot directly write to the Master.<br>However, the master can request data from the Slave.<br>Here is a link to the procedure:<br>https://www.arduino.cc/en/Tutorial/MasterReader<br>
<p>good</p>
<p>hi,can anyone tell hoe to send a variable string using I2c protocol??</p><p>I want to send the variable type String name dataString using i2c protocol,wire library, Wire.write() function </p>
<p>Write a for loop from 0 to the length of the string you want to write and for each iteration just put Wire.wirte(dataString[index]); </p>
<p>hello im quite new to arduino im trying to build a slider for my camera, with a tft screen and a stepper motor, i own a leonardo and a UNO is it possible to link these 2 together for one to work with the motor and the other to work with the screen?</p>
<p>Yes, it is possible and I2C is one of the possible communication protocols which can connect them. </p>
<p>Thanks For explaining the i2c concept</p>
<p>Good Day!</p><p>This is really interesting, thanks for sharing!</p><p>Question though, how's the pin assignments ? Like, if MEGA is master then UNO is slave. D1 on Mega remains as pin 1 and the D1 of UNO would be what in coding?</p><p>Sorry if it doesn't seem clear, I'm learning Arduino :D</p>
Hello,<br><br>I don't really understand your question.<br>The digital pins have nothing to do with I2C, however, in general the pin numbers are the same across Arduinos.<br>For example, if you do digitalWrite(10, HIGH); It will do the same thing on all Arduino models - make pin 10 High...<br><br>Hope this helps.<br><br>You can also check my newly published book: Arduino Development Cookbook by Cornel Amariei on Amazon.<br><br>Best regards,<br>Cornel
<p>OH, because I have an arduino UNO where the pins are all used up (CNC machine). I plan to buy another to incorporate an LCD display to my project, therefore I'll need to connect the LCD pins on another UNO.</p><p>But since Im connecting the two Arduinos together, do I still have to program them both separately or add the LCD codes to the master?</p>
<p>hello i want to make 1 master using mega 2560 and slave using 2 unit uno,how can my mega recognize the address of the uno to avoid sending data mistake,please help me </p><p>regard</p>
Hello,<br><br>The Mega has to be set as master and it has to know the addresses of the 2 Uno slaves.<br>Each Uno slave will have a different address.<br><br>Best regards,<br>Cornel
<p>hi....i want to rum two DC servo motors with arduino uno board, but i know that one uno board can move only two servo motors, but by interfacing two arduino uno, can i able to move 4 servo motors ... with some time delays ofcourse.</p><p>help me plz..in this regard</p>
<p>Hello, I'm not sure if anyone has asked this or not, but doesn't the arduino uno have 2 pins above pin AREF labeled SCL and SDA? Can't these pins be used without interfering with other pins? Plus, is it possible to use the internal pull-ups over externat ones?</p>
<p>In the arduino uno analog pin A4 and analog pin A5 work as SDL and SCL </p>
Hello,<br><br>Yes, If you have a newer R3 board with independent SDA and SCL pins you can use those.<br>Also, no external resistors are required anymore, as they are built in.<br><br>Best regards,<br>Cornel
<p>Hi, I'm having problems, with this stuff. I like to communicate an arduino Mega, UNO and 4 IR temperature sensors ( mlx90614 that use I2C communication ). The Uno will check temperature and send 1 byte if detect a temperature over the range that I will specify and 0 if not. The UNO and the sensors are both slaves (I dont know if this affect), and when I connect only UNO and Mega they communicate passing any data I want, If I connect UNO and the sensors it detect temperature, but when I communicate the 2 arduinos and the sensors the comunication stops and the sensors do not detect anything. How can I fix this?</p>
<p>Hi. I want to use this System with multiple Arduino Mega 2560.</p><p>From what i have understood, I don't need the Voltage connection as long as the devices get the same reference Voltage. So I would only need the CLOCK, DATA and GROUND connection. </p><p>Is that correct?</p>
Hi, that is correct.<br>However, if you have some spare time, test it with and without the resistors and give me some feedback on it.<br><br>Thank you!<br><br>Best regards,<br>Cornel
<p>Hi cornelam,</p><p>I looked into the wiring of the Mega 2560 board itself and found that the SDA and SCL already have each a 10kOhm resistance to 5V build in.</p><p>I work just fine without the external resistors you mentioned.</p><p>Greets CarnefixN</p>
<p>Hello cornelam,</p><p>I connected my 2 Mega 2560 together. The problem is that both of them have the same real time clock 'DS1307' which is in the I2C connection.</p><p>It has a fixed address 0x68(104). Is there a way to deactivate one without having to remove them?</p><p>Greets CarnefixN</p>
<p>Good Day Sir. Thank you for the wonderful guide regarding this protocol. I have tried sending data via I2C, arduino to arduino. numbers that is, or single character data's. If suppose I would like to send an array of characters, say INITIATE_PROTOCOL to another arduino in I2C, how would I assign the variables? will it be char*? Hoping for your reply. Thank you a lot again.</p>
Hello,<br><br>Thank you for the wonderful words.<br>You can attempt the string class, it basically implements the char pointer.<br>http://arduino.cc/en/Reference/String<br><br>Tell me if it worked.<br>Have fun!<br><br>Best regards,<br>Cornel
<p>hello,</p><p>i am doing work on arduino for the first time i want to <br> know that if i have 3 slave ..and all of them are sender and one master <br> receiver how master will address them ...i want code frm master side..</p>
<p>you say &quot;<strong>Devices</strong> have to share both <b>5V </b>(Power) and <strong>GND</strong> (Ground)&quot;</p><p>is there a reason for this? couldnt I just have both devices powered at the same voltage?</p>
<p>They have to get the same voltage reference.</p>
<p>Hey, I'm using this as comms between 2 arduinos. I got it to respond to a photoresistor via the slave but when I tried to add ultrasonic sensor they interact and neither of them work, any idea why?</p>
<p>hi i just wanna ask if i can make an arduino as master at the same time as slave on both arduino?</p><p>or can i send data from master to slave? and slave to master?<br></p><p>kinda confused., </p>
Hello,<br><br>The Arduino only has one I2C Bus, so you can only be either a Master or a Slave at any particular time.<br>A slave cannot write to a Master but a Master can request data from a slave. Here is an example:<br>http://arduino.cc/en/Tutorial/MasterReader<br><br>Best regards,<br>Cornel Amariei
<p>I just came across this instructable today and while the basics work fine, I found out the hard way that you don't need pull-up resistors anymore. In fact it doesn't work if you use them. The Arduinos I tried were Uno, Due and Leonardo and neither of them requires resistors between 5V and SDA or SCL. It's also prudent to look up the SDA and SCL pin mapping for the different types of Arduino (ie: Leonardo: 2 and 3, Uno: 4 and 5, Due, 20 and 21) in the documentation of the wire library: http://arduino.cc/en/pmwiki.php?n=Reference/Wire</p>
<p>Hi</p><p>You might be right about the no need for doing it, but Im using it with Uno and it works fine for me. </p>
<p>Hi. What is max distance between two arduinos allowable ? thank you</p>
<p>Hi... thank you very much for sharing mach valuable information... but i'm having trouble using pin4 and pin5 as i am using a gsm shield.. it consumes pin 4 and pin 5...is there any possibility to use pin 9 and pin 10 or any other pin couple ??? i am new to arduino...thank you very much again...</p>

About This Instructable

407,437views

481favorites

License:

Bio: Inventor, Author, Senior R&D Engineer, Entrepreneur, Forbes 30 Under 30
More by cornelam:Arduino Servo Motors Arduino Distance Sensors Arduino Stepper Motors 
Add instructable to: