How to create a distance matrix using the HC-SR04 sensor?

Search online. There are probably more ways to do this, than people on the planet. You don't need any library to send data to the serial port.