What is wrong. Solved.

while (sensorValue < 500);

Right there.
Eccentric use of braces loses points.