Chances are, you've used some type of a vending machine before. They are useful when you want a quick snack or something to drink, but they sometimes offer games for your entertainment to win a prize, or they have non-edible items inside.
Either way, most of them exist because they're there to make money. They collect your hard-earned cash, and even your coins, in exchange for goods or entertainment. But how do these machines know when you're putting in a real or a fake coin, and how are they able to detect exactly how much money you've put into it?
Special light sensors are built into the machine that measure the thickness of every coin inserted. These sensors can distinguish between pennies, nickels, dimes, and quarters. Moreover, a special electromagnet measures the levels of magnetism from any coin entered such that coins made of non-recognized metals are sent to the return dispenser instead of the coin collector.
In being able to distinguish between change types, this also allows the machine to know what you just paid with and to provide you with the proper change where necessary.