HC-SR04 Ultrasonic Sensor to control Solenoid push rate

Have a look at the blink-without-delay example that is included with the IDE.