HowStuffWorks Autopsy: Inside a Vending Machine


A vending machine is really a simple robot. It has a computer "brain" that controls a bunch of moving pieces. Each of these pieces does a certain job. Here's what's inside:

The central computer is a small box, with a keypad. Using the keypad, the machine's owner can program the machine, telling it what to do when people press the different buttons.

The validator accepts cash. It has a rubber treadmill that drags bills under optical scanners. Each optical scanner is a little camera that sends pictures to a computer. That computer is programmed to look for certain marks in these pictures. If it sees these marks, the validator knows if a bill is genuine money, and it knows how much it's worth.


Not everyone pays with bills. The coin mech takes care of that. Its job is to distinguish between different types of coins.

When you insert a coin, it rolls past a series of electromagnets (coils of wire with electricity running through them). These electromagnets create an electromagnetic energy field. Any metal object - like a coin - will disturb this field. Quarters, pennies, dimes, nickels and fake coins affect the field differently, because they are made up of different metals and vary in thickness. Depending on how the field changes, the coin mech knows what kind of coin you inserted. It sorts the good coins into different stacks and tells the computer how much money you've put in.


The items for sale rest on pairs of metal spirals, which sit on adjustable shelves. Each pair of spirals is connected to a gear, which is connected to an electrical motor. When the motors turn, the spirals rotate and push the food forward.

At the bottom of this machine, there is a line of laser beams. Each laser beam is aimed at an electronic light sensor. When something drops down to the bottom of the machine, it breaks the path of some of the laser beams.

And here's how it all comes together:

  • When you put in money, the coin mech or the validator tells the computer how much you have.
  • When you press the buttons to get something (say, some crackers), the computer turns on the motor connected to the spirals that hold the crackers. The spirals spin and drop the crackers.
  • The crackers break some of the laser beams' path to the light sensors. The light sensors send a message to the central computer, and the computer knows you have your crackers. If nothing passes the beams, the computer knows the crackers didn't drop, so it turns the spirals again. If nothing drops after three tries, the computer tells the coin mech to return your money.