Running a loop once

In the code below the sensor when triggered makes the motor continue going around until the arduino reads the sensor has something blocking the sensor however I want the motor to turn only 90 degrees after the sensor has been triggered and then turn back those same 90 degrees. Thanks for any help.

motr_control_with_PIR.ino (413 Bytes)

The problem I see is that motors don't turn degrees, they turn for a duration. You would be best off having a delay of a few ms, then to accommodate for the acceleration, have it turn the opposite way for a bit longer.

the motor I am using is a stepper motor and so steps is the amount of steps that the motor will take to turn 90 degrees however the motor continues to turn even though it has surpassed the number of steps it is meant to take.

  int val = digitalRead(inputPin);
  if (val == HIGH)

Each time loop() executes, the code is checking that the sensor IS active, but it sounds like you want to detect "sensor has changed from inactive to active" (turn 90 degrees) and "sensor has changed from active to inactive" (turn back 90 degrees the other way).

So you need to detect a change of state in the sensor, not its current level.

In the Arduino IDE, look at File - Examples - Digital - StateChangeDirection.