Vending machine

I 'd like to build a vending machine for 4 kinds of small chocolate bars for my nephew.
I've seen many videos for such a machine (they call it "venduino") but I can't actually understand how to make a motor rotate a full single circle and then stop.
I've got my UNO, 4 simple buttons, 4 NEMA 17 bipolar motors and 4 L298N controllers.
I need to add also RGB led strips: One around the big glass and four small ones around each chocolate box. The general led strip will flash all the time and one small led strip after a button is pressed, when the kid selects which chocolate he/she wants.
I manage with the help of the forum here to light up my led strips and I also got some nice music notes for popular songs as well.
But I make a mistake: I bought a MG995 servo motor which can only return a half circle and then back to its first position. I read 5 books but all of them deal with step motors and simple DC motors. Also, I read this https://www.makerguides.com/l298n-stepper-motor-arduino-tutorial/ .

I have three problems:

  1. I can't find a simple example for "I press a button and a full SINGLE circle of the bipolar motor begins".
  2. I assume that UNO doesn't have all that pins to control the 4 controllers and the 5 led strips. How about If I add a small buzzer to play some music too? Do I have to move to MEGA?
  3. Am I right that I have to power seperatelly (a) the controllers to power the motors with 12VDC and (b) the arduino with 9VDC through it's DC barrel ?

I've already make a 3D model of the machine in Solidworks to choose the right measures, I bought the 4 spirals to put the small chocolate bars in the gaps, but If I can't make it to work I'd be very disappointed.

Is there any book, tutorial or any other help about my 1st question?
Am I right with my 2nd and 3d thoughts?

You ask several questions, so take them in the order of importance.
Since your hardware design is well along the path of using a 360° motor, you could simply put limit switches to stop the motor. If you haven't built the hardware yet, consider using a servo to rotate a plate 180° and let gravity drop the treat. No springs required.

As far as I/O ports, you could use a MEGA (I have no experience with the MEGA), or a port expander like the MCP23017. (How to Connect an MCP23017 I/O Port Expander to an Arduino)

The Port Expander can give you all the I/O ports you need, and if you run out, add another port expander.

For simple music tones, look at the tone() function.

If you already have the servos, you could fabricate a one-way ratchet mechanism that allows the servo to turn the spring 1/2 turn, then the spring remains in position while the servo returns to its start position and applies another 1/2 turn to the spring.

I can't find a simple example for "I press a button and a full SINGLE circle of the bipolar motor begins".

For the button press, see the reference for State Change Detection , as for turning a stepper motor a single turn, you can just blindly drive it the number of steppes needed for a 360-degree turn, but it would be better to have a detector (mechanical switch, IR sensor, hall-effect sensor, etc) to detect the rotational position and use that to detect a complete turn. A disk mounted on the shaft, with a notch or protrusion to activate a microswitch, is a simple, reliable way to do that.

The original "Venduino" and "Venduino 2" (DIY Arcade Cabinet Kits + more. - Arduino Vending Machine) use "continuous rotation" servos. If you take an RC hobby servo and remove the position feedback and physical stops (See: Overview | Modifying Servos for Continuous Rotation | Adafruit Learning System) you get a small bi-directional geared motor with built-in driver. An Arduino UNO can control up to 12 of them using the Servo library.

Looks like the code doesn't bother to use feedback. It just runs the motor at a certain speed for a certain amount of time to get one revolution. Adding an index switch to detect each revolution would not be hard.

One error in the code is using delay(18.5) expecting an 18.5 millisecond delay. The argument to delay() is an integer so 18.5 gets passed as 18. To get 18.500 milliseconds, delayMicroseconds(18500);

johnwasser:
One error in the code is using delay(18.5) expecting an 18.5 millisecond delay. The argument to delay() is an integer so 18.5 gets passed as 18. To get 18.500 milliseconds, delayMicroseconds(18500);

Better, do not use delay() as it means your approach to the program is quite wrong.

You want a "gearmotor" and an index sensor, either microswitch or opto-interrupter. Not limit switches as - you do not want a limit, just continuous rotation and a reference point. This will be reliable and uncomplicated. You will need a logic-level FET to switch the gearmotor.

gnusselt:
2) I assume that UNO doesn't have all that pins to control the 4 controllers and the 5 led strips. How about If I add a small buzzer to play some music too? Do I have to move to MEGA?

Start counting pin connections. You have 18 of them available, plus the two for the Serial interface (which can be used with care).
For better music than some tones, look at the DF Player Mini.

  1. Am I right that I have to power seperatelly (a) the controllers to power the motors with 12VDC and (b) the arduino with 9VDC through it's DC barrel ?

Separate power: correct.

12V DC for the motors: depends on your motor's specifications; do remember that the ancient H-bridge you picked is lossy, so add 2V for that, if you still want to use it. Or take a more modern H-bridge such as the TB6612FNG. Or if you use a geared motor running one direction; a single MOSFET will do.

9V DC to the barrel: no. Regulated 5V to the 5V pin is the much better way; use an old mobile phone charger or so. And now we're at it: consider a Nano instead of an Uno. Much more convenient form factor for anything semi-permanent.

For the dispensing: most vending machines use spirals (a single or double one depending on the size of the product). Rotate the spiral one turn and the next product falls out. No springs involved. I don't see what you're trying to do with springs holding stuff in place.

wvmarle:
Start counting pin connections. You have 18 of them available, plus the two for the Serial interface (which can be used with care).
For better music than some tones, look at the DF Player Mini.

Separate power: correct.

12V DC for the motors: depends on your motor's specifications; do remember that the ancient H-bridge you picked is lossy, so add 2V for that, if you still want to use it. Or take a more modern H-bridge such as the TB6612FNG. Or if you use a geared motor running one direction; a single MOSFET will do.

9V DC to the barrel: no. Regulated 5V to the 5V pin is the much better way; use an old mobile phone charger or so. And now we're at it: consider a Nano instead of an Uno. Much more convenient form factor for anything semi-permanent.

For the dispensing: most vending machines use spirals (a single or double one depending on the size of the product). Rotate the spiral one turn and the next product falls out. No springs involved. I don't see what you're trying to do with springs holding stuff in place.

I think the OP "Springs" == Your "Spirals"

saildude:
I think the OP "Springs" == Your "Spirals"

That's true.

wvmarle:
9V DC to the barrel: no. Regulated 5V to the 5V pin is the much better way; use an old mobile phone charger or so. And now we're at it: consider a Nano instead of an UNO. Much more convenient form factor for anything semi-permanent.

It is absolutely infuriating that we are stuck with the tutorials that suggest the "barrel jack" is actually useful for something, or "Vin".

It is a jolly ornament, a throwback - for compatibility purposes - to a time before ADSL, let alone VDSL - when telephone modems commonly were powered by a 9 V transformer, often with a bridge rectifier and capacitor in a "plug pack" or "wall wart".

A time before 5 V USB "phone chargers" which should now be available for just a few dollars, if not a dollar each from a "garage sale" or "thrift shop".

I mean, for goodness sake! The hardware store is full of them in the electrical fittings department, they now come attached to "power boards", or either included in a power point ("utility outlet") or as an alternative to one, fitted in its own wall plate! :astonished:

And yes, the UNO is a "demonstrator" or "experimental" piece, useful only for an end product where a shield conveniently completes the application, quite inconvenient otherwise.