Ultrasonic Trigger

Hi,

Please excuse my ignorance, I am new to programming.
I am working on a project using an ultrasonic sensor that triggers the turning of a slow geared motor one full, single revolution when a body is sensed within the pre-set range .
I am planning to use a reed switch to determine when the motor has completed a full rotation.

The things I can't workout are:

  1. How to stop the motor triggering more than once if an object (body) remains in the range of the sensor after triggering it the first time. (Basically I want the program to run once and then not again until the body has left the range of the sensor and returned or a new one entered the range).

  2. How to include the reed switch to stop the rotation when closed, but that will be closed when I want the motor to start turning.

Any help on these points would be really gratefully received.
Like I say please excuse me if these questions are answered elsewhere, but I am using this project as a learning curve and a beginning to my learning (after the basic led on/off and traffic lights projects!).

  1. How to stop the motor triggering more than once if an object (body) remains in the range of the sensor after triggering it the first time.

Look at the state change detection example.

  1. How to include the reed switch to stop the rotation when closed, but that will be closed when I want the motor to start turning.

See above. You'll need to wait for two state changes - to open and then to closed.