Adding Ultrasonic distance sensor to STS Roving Robot


I’ve made the STS Pi Roving Robot with the Explorer Hat using a Pi 3B and have it all up and running. I want to add an Ultrasonic Distance Sensor (HC-SR04) to add automatic collision avoidance to my robot but I have no idea on how to wire it up or add the code to my python script. Can anyone help?

But how do I get the distance sensor hooked up to the explorer hat and code it to stop the robot crashing into things?