Hero of Alexandria, a Greek engineer and mathematician who lived in the first century CE, introduced the first vending machine.
For a small fee, you could purchase your very own holy water. A coin was placed into a slot where it fell onto a pan attached to a lever. The lever controlled a valve allowing the holy water to flow.
The weight of the coin caused the pan to tilt until the coin would slide off, and a counterweight restored the pan to its original position, cutting off the flow of water.