The earliest known reference to a vending machine is in the work of Hero of Alexandria, an engineer and mathematician in first-century Roman Egypt. His machine accepted a coin and then dispensed holy water. When the coin was deposited, it fell upon a pan attached to a lever. The lever opened a valve which let some water flow out. The pan continued to tilt with the weight of the coin until it fell off, at which point a counterweight snapped the lever up and turned off the valve.
Coin-operated machines that dispensed tobacco were being operated as early as 1615 in the taverns of England. The machines were portable and made of brass. An English bookseller, Richard Carlile, devised a newspaper dispensing machine for the dissemination of banned works in 1822. Simeon Denham was awarded British Patent no. 706 for his stamp dispensing machine in 1867, the first fully automatic vending machine.
Modern vending machines
An automatic stamp and postcard vending machine, early 20th century, Japan
The first modern coin-operated vending machines were introduced in London, England in the early 1880s, dispensing postcards. The machine was invented by Percival Everitt in 1883 and soon became a widespread feature at railway stations and post offices, dispensing envelopes, postcards, and notepaper. The Sweetmeat Automatic Delivery Company was founded in 1887 in England as the first company to deal primarily with the installation and maintenance of vending machines. In 1893, Stollwerck, a German chocolate manufacturer, was selling its chocolate in 15,000 vending machines. It set up separate companies in various territories to manufacture vending machines to sell not just chocolate, but cigarettes, matches, chewing gum and soap products.
The first vending machine in the U.S. was built in 1888 by the Thomas Adams Gum Company, selling gum on New York City train platforms. The idea of adding games to these machines as a further incentive to buy came in 1897 when the Pulver Manufacturing Company added small figures, which would move around whenever somebody bought some gum from their machines. This idea spawned a whole new type of mechanical device known as the "trade stimulators".