// Arduino MKR sur Arduino MKR Connector // Connexion sur le connecteur SERIAL #include SoftwareSerial ser(A4,A5); // initialize a serial connection (software) float distance; long int bytes[3]; void setup(){ Serial.begin(9600); // start serial connection to computer ser.begin(9600); // start serial connection to sensor } void loop(){ ser.flush(); // clear communication ser.write(0xA0); // start measurement delay(200); // Wait 200 ms for (int i = 0; i < 3; i++) bytes[i] = ser.read(); // Read 3 bytes from sensor 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 }