Motor and sensor

for (int i = 0; i = 0; i++) // we turn the motor

    for (int i = 0; i = 50; i++)

Neither for loop makes sense. You're also re-using variable i in the inner loop.

The second would probably needs to be something like:

    for (int j = 0; j < 50; j++)

The first... just doesn't make sense.