


BONUS: I made a quick start guide for this tutorial that you can download and go back to later if you can’t set this up right now.Throughout my various Arduino-based projects I have made use of quite a number of excellent libraries that are not part of the standard Arduino IDE. It covers all of the steps, diagrams, and code you need to get started. The I2C NetworkĪn I2C network consists of a master device and a slave device. The master and slave devices are connected by a bus. I2C networks can have multiple master devices and slave devices. Slave DevicesĮach slave device has an I2C address that is used to identify the device. The I2C address makes it possible for a master device to send data to a particular slave device on the bus. Master devices can send and receive data. Slave devices respond to whatever a master device sends. When sending data on the bus, only one device can send data at a time. The BusĪn I2C bus is simply two wires that connect all of the I2C devices in the network.

The SDA wire is used for sending the actual data back and forth between the master and slave devices. The SCL line carries the clock signal used for communication timing. Pull-up resistors are used to keep both wires in a HIGH state by default. The Arduino outputs I2C signals at a 5V logic level. An I2C device that operates at 3.3V could be damaged if connected to the Arduino.īut I2C devices can operate at a range of different logic level voltages. The device’s datasheet should tell you it’s logic level voltage. To learn more about the details of I2C communication, check out our article on the Basics of the I2C Communication Protocol. To demonstrate how to use I2C on the Arduino, let’s build a project that sends data back and forth between two Arduinos. This project will read the position of a potentiometer connected to a master Arduino, send the information over I2C, and change the blink rate of the LED on the slave Arduino. The Arduino has dedicated pins for I2C, which have built-in pull-up resistors as required by the I2C protocol.įor Arduino Uno boards, these are pins A4 and A5. In the Arduino Uno R3 version, there is another set of I2C pins near the USB socket: Pin A4 is the SDA pin, and pin A5 is the SCL pin. We don’t need pull-up resistors on the SDA and SCL lines, because they’re built into the Arduino’s I2C pins already. We have two Arduinos in our I2C network, so we have two sets of sketches. Wire.begin() // join I2C bus as the master Int stat_LED // status of LED: 1 = ON, 0 = OFFīyte value_pot // potentiometer position Unsigned long time_start // start time in milliseconds Open the Arduino IDE and upload the code below to the master Arduino: // Arduino master sketchīyte i2c_rcv // data received from I2C bus One is for the master Arduino, and the other is for the slave Arduino.
