trouble with HC-SR04 and 5V DC motor

Work out how to read the distance (The example code you posted does this)

No, it doesn't - read it.