// Include Arduino Wire library for I2C #include // Define Child I2C Address #define CHILD_ADDR 9 // Define Child answer size #define ANSWERSIZE 5 #include "Ultrasonic.h" Ultrasonic ultrasonic(1, 2); // Trig et Echo void setup() { pinMode(4, OUTPUT); pinMode(5, OUTPUT); // Initialize I2C communications as Father Wire.begin(); // Setup serial monitor Serial.begin(9600); Serial.println("I2C Father Demonstration"); } void loop() { delay(3000); int dist = ultrasonic; // Write a charatre to the Child Wire.beginTransmission(CHILD_ADDR); Wire.write(0); Wire.endTransmission(); Serial.println("Receive data"); // Read response from Child // Read back 5 characters Wire.requestFrom(CHILD_ADDR,ANSWERSIZE); // Add characters to string String response = ""; while (Wire.available()) { char b = Wire.read(); response += b; } // Print to Serial Monitor Serial.println(response); }