# Candy Vending machine, how to limit the amount of servos needed?

I'm making some plans for a vending machine that is to be used for dispensing candy in my home.I went for the spiral method (please tell me if there's a better method).

I got all the plans laid out and i got most of it working already.

The problem is: I want to limit the number of servos this project is using. Servos are expensive and they take precious pins on the arduino i'm using for the project.

The question is: I have 9 spirals for candy and i would need 9 servos to turn them and release candy (nom nom).

Is there some ingenious way to limit the amount of servos and still be able to rotate all the spirals independently?

This is basically what i'm making, just smaller :)

I edited it to include a little flash file i made of a rail system using 2 servos and an aktuator.

sort by: active | newest | oldest
steveastrouk7 years ago
Here's a circuit using a 2803.
Eirinn (author) 7 years ago
To be honest it's not really the pin count that's the problem - it's the amount of servos itself and thus the money that needs to disappear from my pocket. The required servos could possibly be driven off an arduino mega which has an abundance of pins. If i could limit the project to use...say.. 3 servos the project price would be cut in half. I've thought about making a mechanical gearshift, but no matter how i look at it, it will either be too complex or unreliable.
7 years ago
Since the number of spirals is relatively small (9, not 50), what about something like this? Put the main servo motor on a movable stage, controlled with something less expensive like a pin actuator. Have a gear on the servo axis engage with a stack of N gears adjacent, and use the actuator to move the servo from position to position.

If you use relatively thick gears, separated by their own width, then the servo can't engage two at once, and you get a fair bit of slop in the alignment tolerance.

Theoretically, you could use the tri-state output from a single pin to drive the actuator (+ == forward, 0 = center, - == backward), if it was set up that way.

What isn't obvious to me is whether this is cheaper than servos or not. A quick Google search found pneumatic actuators for \$15-20, or \$100 or more!

7 years ago
Forget the "servo" bit, all you need is a motor that turns a shaft once or whatever. Why does it need to be a servo.
Eirinn (author)  steveastrouk7 years ago
It has to move the spiral a specific amount so it doesn't dispense a flood of chips - just servos came to mind. Ideas for cheaper alternates are always well received :D
7 years ago
Could do with a picture of what you're doing to give you some better ideas
Eirinn (author)  steveastrouk7 years ago
Right, i have the plans on paper, i'll see if i can get my scanner working under windows7. http://labs.myrtlestreet.org/wp-content/uploads/2009/07/candy_machine_921kb_cp4d.jpg This is the closest i can get, just picture that with 9 "purchasable" items. I know how to handle everything but limiting the amount of servos needed.
7 years ago
Alright, here's a simple circuit, for a single spiral. It needs a double pole, double throw relay, and little switch which is bumped by the spiral after one revolution.

Switch on the transistor, for long enough that the spiral turns off the switch.
The relay latches ON.
Turn off the transistor.
Now the spiral will turn, until the bump switch is hit, this opens the relay, and the spiral stops.

The limit switch must be CLOSED until the spiral has turned once.

Steve
Eirinn (author)  steveastrouk7 years ago
Thank you for this. This method sounds interesting, however i'll have to ask you to elaborate - i'm not quite getting it.

In this schematic a normal DC motor is used?

Is there a way to slow the motor down since it would otherwise be likely to fling out the items? Or is this already acounted for?

I've got some substantial experience working with resistors, capacitors, servos, arduinos and LEDs. I haven't worked with transistors, relays and diodes yet.
7 years ago
Yes, a plain DC motor.

Speed ? Feed the motor from an LM317 adjustable regulator. I can add that to the diagram later if you like.

You can use a "ULN2803" to drive the relays, I'll add that too.

Steve
Eirinn (author)  steveastrouk7 years ago
Thank you :D I added a SWF to the original post that uses 2 servos and an aktuator - what do you think would be cheapest, the current diagram or the idea represented in the animation?
7 years ago
Getting the mechanics right would be very tricky.
Eirinn (author)  steveastrouk7 years ago
Yeah and it might be unreliable even if it works. I'm thinking of either adding servos as i get the money for them thus slowly build up 9 item dispensers or going with a DC motor solution. The problem for me is that using servos is extremely easy as the arduino handles all the driving. All i have to tell it is how much it's supposed to rotate and it will do exactly that. Using a diagram like the one you posted is probably the best solution, but i don't have the necessary electronic knowledge to completely understand how and why it works; well i understand the process just not why each component has to be at that specific location and so forth. I'm sorry if have wasted your time due to me not knowing enough about electronics to complete and understand a diagram like the one you posted... it even seems relatively simple. I have no electronics education - the first project i made was clamping a few wires together with my fingers and get an LED to light up by throwing a switch (hadn't learned to solder back then). My knowledge is based on components i've used before and i feel confident in using due to me knowing how to solder and handle them while knowing why it does what it does. That is why i'm pretty lost when relays and transistors come up - i guess that just means i have to read up on them. I know it was a lengthy explanation, i just wanted to clarify :)
7 years ago
Just ask, I'll happily clarify it for you. The point is, with the spiral system, you have to have continuous rotation, which the servo isn't designed to do, and costs more than it needs.
Eirinn (author)  steveastrouk7 years ago
There's continous rotation servos though :3 and a normal servo with a single rotation can be modded for continous drive. Alright i'll try to figure out some questions.
7 years ago
How much do they cost, and how much extra programming will you need ? All these things I drew need is a pulse to say "dispense one candy bag"...... Steve
Eirinn (author)  steveastrouk7 years ago
I had a thought. If i use a DC motor it will turn until it is turned off and/or the velocity drops. When a DC motor turns off afaik it doesn't just stop it continues until it loses its momentum. This will be a problem when using the spiral method as it will at some point be bonked out of tune since not all wares will weigh the same. Also is it possible to just use an analogue pin and turn it low/high to control a DC motor? I bet it can be done, but i've read somewhere it can be harmful for the arduino.. for some reason i don't understand.
7 years ago
It doesn't matter, because the microswitch will resynch the thing regardless of speed.

Braking: Turn AA2 around, and put the common connection to the motor, the normally closed contact to the motor supply and the normally open to ground. Now its dynamic braked, and stops very fast.

You can't switch more than a few mA with an arduino pin directly, they have to drive transistors, or ULN 2803s to drive anything significant.
Eirinn (author)  steveastrouk7 years ago
I could probably manage to make the circuit, but i'm reluctant to do so since i don't understand how it works.

The servos are really simple for me since it's a matter of turning a servo on/of and specifying rotation through code.

The benefit of this, is that it requires me to have more knowledge of programming and less knowledge of electronics. I've controlled several servos before and interchanged between them without flicker no problem.
They are also accurate unlike any other motor i've worked with and seem incredibly stable. All i'd have to do is to buy 9 full rotation servos and turn one on when needed - then issue a command for a full revolution.

I'm aware the schematic you posted does the exact same thing for a much lower price at the cost of some extra work.

I think the problem for me is that i don't understand the circuit. I'm reading up on transistors at the moment, but i think by the time i'm done reading and i fully understand the circuit i'll be long over this project - no offence meant! It's just that i have a programmer background making the coding much easier.

I'm not sure what to do :S

7 years ago
The servos I've seen only more 120 Degrees at most, when altered to "constant rotation" they are off, forwards, or backwards.

Here's how the circuit works.

The transistor is a switch here. Switch it on - pulse it for half a second at most.

What happens ? The relay closes.
What happens ? The contacts AA1 and AA2 switch over. The limit switch stays closed.
What happens ? The motor turns, because AA2 is closed. The relay LOCKS on, because AA1 is closed.

Turn off the transistor switch.

What happens ? The relay STAYS energised, the motor STAYS on, because AA2 and AA1 stay closed.

The limit switch opens.
What happens ? the relay OPENS, AA1 opens, AA2 opens. The motor stops.

The cycle completes.
Eirinn (author)  steveastrouk7 years ago
Hi Steve,

I was so lucky as to get a whole bag of candy machine spirals and appended motors. And guess what, the circuit as pretty much like the one you posted using a 12v dc motor, a switch and a few extra components.

Now the only thing i need is a way to combine that with my arduino. I'd really like to avoid using relays since they're pretty expensive (almost the same price as a cheap servo). Could a few transistors do the trick?

If you want i can post the circuit and a photo of the actual thing. Hope you're still getting these comments.

- Regards Eirinn
7 years ago
Well there's these, which work out about 1 Euro each.
http://uk.farnell.com/multicomp/hrm1-s-dc12v/relay-pcb-dpco-12vdc/dp/9479953

Eirinn (author)  steveastrouk7 years ago
Doesn't farnell deal with businesses only?

http://elektronik-lavpris.dk/index.php?cPath=5802_5808&sort=3a&page=1
( http://elektronik-lavpris.dk/index.php?cPath=5802 <--- overview and more relays)

Would any of these do? I'm guessing i'll need 9x 12v DPDT 1A. The reason i'm listing that site is that i'm going to order some stuff from them anyway.

(I checked how many amps the motor was pulling and it seemed to me like it was drawing less than 0.1A using a bench power supply. I sadly didn't get to test with a multimeter).

Also what does double pole double throw mean? :)

Thank you again - Eirinn
7 years ago

http://elektronik-lavpris.dk/product_info.php?products_id=88723&language=en
Eirinn (author)  steveastrouk7 years ago
Got the stuff with the mail the other day i'm really excited about all of this. The relays are smaller than i thought they would be, which is awesome since i'm going to make a custom pcb to fit it all. I got the schematics for the (and checked if it's working) RFID, the Numpad and the mechanical chassis down. What's left is the motor circuit which still has me baffled.

If the uln2803 was laid out as a normal transistor i maybe could make heads and tails out of it. But it seems to have a shared pin and protective diodes in one package....which is probably great, but pretty confusing. Which is the collector, emitter and ground?....well i might have ground down.

I've spent a great deal of time searching for information about coupling an uln2803 to a standard 12v relay. But all the information i get is semi-confusing and the only thing i seem to have gotten down is that pin 9 goes to arduino ground. I simply can't find a decent page that lists a circuit using a arduino connected to a Darlington IC driving a relay.

http://blog.makezine.com/archive/2009/02/connecting_a_relay_to_arduino.html
Is the closest i've gotten, but that one uses a standard relay. Since i have no idea what's B/C/E on the Darlington i can't connect it like on the diagram and i'd rather not fumble and break something. Also there seems to be a diode connected parallel to the coil. Is that needed when the Darlington IC has them built in?

If i could just get one chain working and rotate the spiral for a full revolution i could easily make out the rest.

So excited :D
7 years ago
Nah, they'll take anyones money. RS used to be VERY sniffy, but times is hard....

Double pole double throw - two switches, each with changeover contacts.

Steve
Eirinn (author)  steveastrouk7 years ago
Awesome, they got a lot of neat stuff.

As i can tell i'd need 9 relays for 9 circuits right? - i tried reading the datasheet but couldn't find a pinout and the markings on the top doesn't seem familiar.

Would i still need transistors with this? It's all very confusing, but it's slowly getting there.
7 years ago
Use a "ULN2803" to run 8 relays - sorry, you need 2 for nine relays !

Steve
Eirinn (author)  steveastrouk7 years ago
Allright, i think i'll write down the diagram for the spiral circuit and then present it, that should also help clear up my confusion.

What i get so far:
As i can tell the need of relays is because the arduino can't drive dc motors off the pins due to a (presumably) 50ma max output from each pin. Therefore the motors have to be controlled externally, and be switched on and off by relays. This also should prevent from flyback electricity that could potentially go back into the arduino pins (the motor circuit seems to have diodes for this though).

That makes one relay per spiral/motor circuit. I'm not sure i know why the transistors have to be coupled to the relays (i know you've tried to explain it earlier).

I hope i'm right so far hehe.
7 years ago
I'm not sure i know why the transistors have to be coupled to the relays (i know you've tried to explain it earlier).

because its not a good idea to put relay loads on processor pins. The 2803 contains all the transistors you need.

Steve
Eirinn (author)  steveastrouk7 years ago
Allright - so a transistor is needed as to not stress the microcontroller pins due to the coil activation.

I've read a little about transistors and it seems the IC you linked is a darlington transistor pack containing several transistors.

I've googled transistors and this is what i found:
"Transistors cannot switch AC or high voltages (such as mains electricity) and they are not usually a good choice for switching large currents (> 5A). In these cases a relay will be needed, but note that a low power transistor may still be needed to switch the current for the relay's coil! "

However i'll be switching less than 1A and only 12V DC so i'm a little confused as to why a relay is needed. Couldn't i just use a high power transistor like the darlington paired ones?

Aaah hope i don't sound too stupid, i'm just trying to understand :)
7 years ago
You don't get the isolated but related switches that the design needs, unless you do it the way I've drawn it, and the designers intended.

Transistors are a great solution for currents up to several hundred amps, in the right conditions: this isn't one of 'em. An all transistor solution is possible, but here it would likely be more expensive and less reliable.

Steve
Eirinn (author)  steveastrouk7 years ago
I'm going to begin and order tthe parts, just to be sure:

2x darlington transistor packs

Would be all that is needed to control the motors circuits?

Also i'm going to run two ATMEGA328 together over I2C for this project - this is not a problem (tested and it seemed to work fine). However i want to add an RTC like this one (pre-packaged brick, it's easier):

http://www.let-elektronik.dk/index.php?page=shop.product_details&flypage=flypage.tpl&product_id=102&category_id=12&option=com_virtuemart&Itemid=76

However the connection type is also I2C and i'm already using those pins to connect both arduinos to each other. Is there a workaround or is there a way to do it?

The RTC is going to be used to add "currency" to the vending machine every day or week so the candy intake is limited to a fixed daily or weekly amount. It's not 100% needed since i could just beep an RFID chip and that would add a certain amount of "currency" to an "account". But having it doing it automatically would be nice :)

All your help is greatly appreciated!
7 years ago
Looks like all you need there.

Well, I2C is an addressed protocol, just change the address of your Atmega to make sure it doesn't clash with the RTC.

Steve
Eirinn (author)  steveastrouk7 years ago
Oh also, i've been thinking.

Couldn't one use an optoisolator for this? I'm sure there's a reason for why not, but i remember people using them to switch on/control 12v DC motors.
7 years ago
Nope. Won't do the same job as the relay drivers. Not enough current carrying capacity
Eirinn (author)  steveastrouk7 years ago
I've looked at the pinouts of the transistor packs and the relay and i'm not sure how either of them work.

Well...i mean i kind of understand how a relay works. When energizing the relay it either switches on or off - a switch that changes ON or OFF depending on a state that can be changed by electrical current.

As i can understand the relay's two bottom pins are the coil pins and the three top ones are a normally open,a normally closed and a common pin? I'm not entirely sure about the wiring - especially regarding the transistor pack (never had to to with transistors before and certainly not darlingtons).

Any chance you could help me with the relay circuit again? I could probably put it together by schematic, but i really want to go through the learning process too.
Eirinn (author)  Eirinn7 years ago
Uh by three top ones i mean on either side - there's of course 6 pins.
Eirinn (author)  steveastrouk7 years ago
Amazing, it seems like i'll finally be able to make the machine :D

Now the only thing i'm iffy about is the wiring since it has changed due to the new circuit.

I've got this so far:
The arduino pulses the transistor pack's pins (depending on which relay needs to be opened). Then the transistor opens the relay until the microswitch turns on again (i'm not sure of the switch type if it's OFF at default or ON).
- Then it dispenses one serving of sugary goodness.

What i'm unsure about is the actual wiring.

I'll be sure to document the entire process here on instructables, i'll of course have your name in it too :D
Eirinn (author)  steveastrouk7 years ago
Alright :D

I've attached what i can make out regarding the circuit. I know it's not a real schematic, but it shows the physical connections and locations (connections top, physical components under) It's a one sided pcb.

I hope this helps to understand the spiral circuit.
Eirinn (author)  steveastrouk7 years ago
Oh and the spiral circuit has a built in microswitch which is turned on when the motor is running and off when it has done one revolution. It also seem to have a resistor and a few diodes.
7 years ago
7 years ago
Try this one.
7 years ago
.... That's what I was thinking; you described it better than I.
7 years ago
Usually, the spiral is set such that a single complete rotation dispenses one unit of product. Then all you need is a motor with a cam and a microswitch such that once it starts running it continues running until it completes that rotation and the cam turns it off again. Motors and microswitches can be scavenged a lot more easily than servos, and are less complicated to operate.
Eirinn (author)  kelseymh7 years ago
Yeah agreed - I also thought of some kind of x-y rail system for a mechanic/electrical approach using cogs, but it always ends up seeming a bit unreliable. As steveastrouk says though it doesn't actually have to be servos, but i'd like for the candy to be dispensed with a very small error margin. If the motor runs too fast there's risk of candy projectiles and/or uneven dispensing. Actuators may be a solution, but aren't they 12v and over? I have next to no expertise in using actuators.
steveastrouk7 years ago
HI Eirinn,

What do you need clearing up ? A walkthrough the circuit again, or how the darlingtons need wiring ??

Steve
Re-design7 years ago
Use stepper motors. I've seen them surplus for as little as \$2 each. Try to get a dozen of the same kind so that they are all alike and you have a couple of spares if needed.
Eirinn (author)  Re-design7 years ago
I checked the price of steppers where I am and they're almost the same price as servos :/ could try ebay if i choose to go with steppers. Thanx Eirinn.
7 years ago
Eirinn (author)  Re-design7 years ago
I'm not American...in this case unfortunately cause that's cheap! Would be awesome if i could use low cost steppers instead of servos, but I'll have to find a European provider (preferably a Danish one).
steveastrouk7 years ago
There are several ingenious ways of doing it, it depends how good your coding skills are - a serial/parallel converter, like the 595 gate will let you run 8 or 16 or more servos on the SPI pins on the arduino.

I don't know what happens to a servo if you take the PWM input off, and tie it high or low ? Will it freeze, or will it just slam to one end or the other ?

Steve
Eirinn (author)  steveastrouk7 years ago
I think it will go at max speed in the direction specified by the polarity... since you're effectively cutting it's driving mechanism. I guess this could work since doing this modifies it for a direct drive.
7 years ago
Servos don't have a polarity, they expect a PWM signal, with a 50Hz frequency, and a 20--200uSec period AFAIR. Steve
Eirinn (author)  steveastrouk7 years ago
Fair enough i'm no expert :D i've noticed people modding them for direct drive though if that helps any.
kelseymh7 years ago

I don't think you can limit the number of servos, not without some even more tricky (and control-pin consuming!) "gearshift" system. But you might be able to reduce the number of control pins from 9 to 4.

For the real electronics experts out there -- would a charlieplexing setup work for this application? (Charlieplexing allows n tristate controller pins to drive up to n2-n LEDs.)

Instead of LEDs, I'm picturing just regular diodes to restrict the current to just the desired channel, with the servo on the "output" side of the diode. The controller wouldn't need to do the fast-flicker POV stuff that charlieplexing ususally entails, just hold the output pins in the right state for the servo to make one rotation.

There is probably some obvious engineering reason why this is a bad idea, but I'm throwing it out there anyway.

Eirinn (author)  kelseymh7 years ago
I've heard about charlieplexing before, maybe it's time for me to check out the benefits of plexing in general. Thank you for the comment whether or not it leads to a solution for the vendor machine :) I'm making this with an RFID user account system so we can effectively limit the amount of candy that gets eaten per day in the household :)
7 years ago
I can't see how charlie-plexing helps here, Some form of multiplex, sure, but a C-plex not really - its an LED drving scheme and little else.