#include //include the library #define device (1) //define master #define SLAVE_ADDRESS 0x6 //define the address for the slave #include //add library to be able to use the serial monitor int rxPin = 0; //the receiving pin int txPin = 1; //the transmitting pin SoftwareSerial serial(rxPin, txPin); // to set up the serial object void setup() { TinyWireM.begin();//setup initialization pinMode(rxPin, INPUT); //the rx pin is the input of the communication pinMode(txPin, OUTPUT); //the tx pin is the output of the communication serial.begin(9600); //begin communication with computer } void loop() { TinyWireM.beginTransmission(SLAVE_ADDRESS);//begin transmission to slave address TinyWireM.send(1);//send "1" TinyWireM.endTransmission();//end the transmission msg();//receive message delay(2000);//wait 2000 millisec TinyWireM.beginTransmission(SLAVE_ADDRESS);//begin transmission to slave address TinyWireM.send(0);//send "0" TinyWireM.endTransmission();//end the transmission msg();//receive message delay(2000);//wait 2000 millisec } void msg() { volatile byte msg =0; //treat as variable TinyWireM.requestFrom(SLAVE_ADDRESS,1);//request from slave address if (TinyWireM.available()){ //to make sure the master is available msg = TinyWireM.receive();//receive message if (msg ==4){//if this message serial.println("Slave LED off");}//print this in serial monitor else if (msg ==5){//if this message serial.println("Slave LED on");}//print this in serial monitor } }