The number in the argument is the address we want to use for the Arduino.
We also include the Wire.h library here, but now we start the I2C bus using Wire.begin(9). Now let's explore the slave Arduino code. We use the following functions to begin a transmission to the device with the address 9, write the character, and then stop the transmission: Wire.beginTransmission(9) // transmit to device #9 Lastly, we send a character x, which is between 0 and 5. If no argument is provided in the function, Arduino will start as a master. Then, in the setup function, we begin the I2C bus using the Wire.begin() function. We need to include the required Wire.h library: #include If value received is 3 blink LED for 400 msįirst, let's look at the master. If value received is 0 blink LED for 200 ms X = Wire.read() // read one character from the I2C Attach a function to trigger when something is received. Start the I2C Bus as Slave on address 9 If (x > 5) x = 0 // `reset x once it gets 6Īnd here is the slave code that interprets the characters sent from the master: // Include the required Wire library for I2C#include Wire.endTransmission() // stop transmitting Wire.beginTransmission(9) // transmit to device #9 First, let's take a look at the master code: // Include the required Wire library for I2C#include The following code is split in two parts: the master code and the slave code, which run on two different Arduinos.