Vending machine cabinet
A vending machine cabinet: four spiral slots on continuous servos, a snack in every coil, and an infrared beam across the bin.
Turn a spiral once and its front snack tips off the end and drops through the beam into the bin, where the sketch's drop sensor sees it go.
Pins
| Pin | What it does |
|---|---|
M1 M2 M3 M4 |
The spiral servos' signals, for slots A1, A2, B1 and B2. |
VCC, GND |
5 V for the four servos and the drop sensor. |
DROP |
The drop sensor's output: LOW while the beam gets through, HIGH while a snack falls through it. |
Each spiral is turned by a continuous-rotation servo and the drop sensor is a slotted optical switch module, the parts a home build uses, on the pins they have on the bench. A sketch written for loose servos and a loose sensor runs the cabinet unchanged.
How it moves
Each servo is an FS90R: a pulse of 1500 us stands it still (and so does the
Arduino library's write(90), 1472 us, inside its dead band), and 500 us
either side is full speed, 110 rpm (rpm). write(180) turns a spiral the
way that brings its snacks forward; write(0) winds them back.
Each slot holds stock snacks (3), one a coil. A turn moves every snack one
coil towards the glass, and the front one tips off the end about four fifths
of a turn in. So a sketch that runs a spiral for one turn, 560 ms at full
speed, sells exactly one snack, and the next one is left a fifth of a turn
from the edge.
The drop
Row A's shelf is 30 cm above the bin and row B's 18 cm. A snack falls under gravity and the beam crosses the bin 4 cm up, so it is broken for about 20 ms as the snack goes past. Watch for the pin to go HIGH and you know the sale really happened.
A spiral with nothing left in it turns and drops nothing, which is how a real machine's failed vend looks to its sensor. The round arrow on the cabinet fills every spiral again and empties the bin; so does every Run. A sketch's own stock count and the spirals can disagree: restock in software without filling the spirals, and the beam tells the truth.
What the model gets right
- The servos are the servo model in continuous mode: the same neutral, dead band and full speed, and no motion under 4 V.
- The drop sensor is the photo interrupter model: LOW when clear, HIGH when blocked, floating below 3 V.
- Everything is deterministic: the same sale drops the same snack the same way.
What it does not model
- A snack catching on the coil and hanging there. Every snack falls when its turn comes.
- Snacks of different sizes, and the servos' current.