Problem with stopping a servo with Sensor Value

Dear forum users,

i have got a problem with programming the servo in arduino. I want the servo to go to certain value with a for loop. The servo should go from 180 to 0 in 1 degree steps and should stop if a value of a sensor is exceeded. Here is the for loop that I wrote:

if (button2Status == HIGH) 
    for (pos = 180; pos >= 0; pos -= 1) 
     if(FSRvalue > 900)

The problem is, that it does not stop if the sensor value is exceeded.

It would be very kind if someone could help me :slight_smile:

You only posted a portion of your code.
Please post the entire sketch.

There's nothing in that for loop code fragment that changes FSRvalue. So the only way it will break is if FSRvalue is > 900 when the for loop starts (since for loops are blocking code). Is that what you intended?