Problem programming a conveyor to stop near a proximity sensor

Once you understand how to use the Arduino and forum, this looks like a great place to apply a ‘state machine’.