Problem programming a conveyor to stop near a proximity sensor

I need help writing the code for an Arduino. We are trying to automate a cookie making process and would like to get part of it to work. A bowl will start at its home position on a conveyor and will move to position 2, which is located directly in front of a proximity sensor. Once the bowl stops at position 2 this will then actuate an auger motor that will dispense brown sugar in the bowl. The bowl must remain at position 2 for 24.8 seconds (the time it takes to dispense all the brown sugar into the bowl).

I need help writing this code! Thank you!

Arduino Cookie Bowl Positioning and Brown Sugar Dispensing.PNG

I need help writing the code for an Arduino. We are trying to automate a cookie making process and would like to get part of it to work. A bowl will start at its home position on a conveyor and will move to position 2, which is located directly in front of a proximity sensor. Once the bowl stops at position 2 this will then actuate an auger motor that will dispense brown sugar in the bowl. The bowl must remain at position 2 for 24.8 seconds (the time it takes to dispense all the brown sugar into the bowl).

I need help writing this code! Thank you!

Arduino Cookie Bowl Positioning and Brown Sugar Dispensing.PNG

(deleted)

The essential first step is to pick a proximity sensor and verify that it works in the intended environment.

Come back when that is done, with much better project specifications. Those will include full details of the chosen sensor, and how the belt is powered and controlled.

Maybe check out this thread, seems like a similar problem.
https://forum.arduino.cc/index.php?topic=540939.msg3686566#msg3686566

Maybe check out this thread. Seems like a similar problem.
https://forum.arduino.cc/index.php?board=4.0

Do not double post.

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

MilkMan406:
We are trying to automate a cookie making process and would like to get part of it to work.

Is this a real application, or a college\school proramming exersise ?

You need to give it try yourself first.

@MilkMan406, please do not cross-post. Threads merged.

Ok, so the system has three "states"

1 - moving the bowl into sensor range. lets call this 'get_bowl'
2 - pause while the bowl fills. let's call this 'fill_bowl'.
3 - moving the bowl out of sensor range. Let's call this 'bowl_done

The transition from one state into another is caused by an external event. When the transition happens, the arduino needs to do something.

In state 1, a transition to state t happens when the sensor detects the bowl. The sketch needs to stop the conveyor, start pouring, and make a note of the current time

In state 2, the transition to state 3 happens when the time runs out. The sketch needs to stop pouring and start the conveyor

In state 3, the transition back to state 1 happens when the bowl moves out of sensor range. The sketch doesn't need to do anything but go back to state 1.

I like using enums and switch cases for this sort of thing:

enum State {
  GET_BOWL, FULL_BOWL, BOWL_DONE
} state = GET_BOWL;

uint32_t fillTimer;

void loop() {
  switch(state) {
  case GET_BOWL:
    if(the sensor has detected the bowl) {
      turn conveyor off;
      turn filler on;
      fillTimer = millis();
      state = FILL_BOWL;
    }
    break;

  case FILL_BOWL:
    if(we have been filling for 24.8 seconds) {
      turn filler off;
      turn conveyor on;
      state = BOWL_DONE;
    }
    break;

  case BOWL_DONE:
    if(the bowl is no longer being detected) {
      state = GET_BOWL;
    }
    break;
  }
}

like that.