I am building a bead dispenser, and I made some good progress so far. Users can input the number of plastic beads they want to receive. Let’s say a user enters 3. The stepper motor will start to rotate and if a single bead is falling through a hole in the dispenser, it will break the IR beam and the counter gets incremented. If the counter is equal to the user’s input the motor will stop.
The code of this scenario is here:
During development, I noticed that if Arduino is turning the stepper motor it is blocking subsequent code. Subsequently, I am actually performing the check if the IR beam was broken. Because of the blocking behavior, I ended up making the step size as little as possible (i.e., 1 — (see lines 90 and 91).
This code is working okay. Let’s say the accuracy is around 80%; however, I am looking for a different approach:
I am a freshman in the Arduino sphere but I guess there must be a solution to instruct the Arduino to rotate the stepper motor independently from IR beam breaker. However, once the input is satisfied, the motor should also stop and wait for new input.
I am trying to make a video now, I guess this could be helpful.