// Arduino MKR sur Arduino MKR Connector // Connexion sur le connecteur TWI #include int address = 0x57; // i2c address of SEN-US01 float distance; long int bytes[3]; void setup(){ Serial.begin(9600); Wire.begin(); } void loop(){ Wire.beginTransmission(0x57); // Start measurement Wire.write(0x01); Wire.endTransmission(); delay(200); // Wait 200 ms Wire.requestFrom(0x57,3); // Read 3 bytes from sensor int i = 0; while(Wire.available()){ bytes[i++] = Wire.read(); } distance = ((bytes[0] << 16) + (bytes[1] << 8) + bytes[2]) / 10000; // Calculate distance based on received bytes if (false){ // Checking whether measured value is within the permissible distance Serial.println("distance is outside of the measuring range"); // If not, an error message is output } else{ Serial.println("distance: " + String(distance) + " cm"); // The calculated distance is output to the console } delay(3000); // Pause between the individual measurements }