How do modern vending machines know what coins you’ve inserted? Well, according to this fantastic CG animated segment from the Science Channel, current day vending machines make use of a combination of light sensors to accurately measure the size of the coin being dropped in, and electromagnets to determine the metal type of the coin rolling past. Together this information provides the onboard computer with enough information to make a pretty accurate guess as to what coins have been inserted, allowing it to then calculate and distribute change if necessary.
A bonus for anyone who has ever had a fight with a vending machine before, modern machines detect whether or not an item has dropped into the retrieval chute by means of light beams – and if nothing has indeed dropped down, the computer simply tries again! (That would have saved me a LOT of frustration in my university days!)
Related Link: Science Channel