For a long time, physicists and chemists debated whether heat was a fluid (like a mysterious liquid) or came from the motion of particles. Many early scientists, like Newton, had thought that heat might be caused by small movement of particles, and greater heat meant greater velocities or kinetic energies. Lavoisier, however, thought that heat was a massless fluid that he called "caloric".
Count Rumford observed that the process of boring cannon (drilling the hole in the middle of the brass cannon) produced a lot of heat, especially when the drill was dull or blunt. He showed that the heat produced was related to the amount of mechanical work done by the drill. Davy (mentioned earlier here) showed that even at 0°C, two ice cubes would melt when rubbed together. This frictional heating is also a way that people sometimes start fires in the wilderness.
Other scientists liked the fluid theory. Lavoisier thought heat was a fluid that caused the atoms it surrounded to separate (which is why, he said, density usually decreases as you heat a substance). One important contribution he made was to show that the heat generated by human or animal metabolism (oxidizing food with oxygen from breathing) produces the same amount of energy as combusting the food (which is often if not always true). Carnot, who will be very important later (in the development of the second law of thermodynamics), also thought that heat was a liquid, because like liquids it "flows downhill" from hot objects to cold objects. He thought that like power generation from a waterfall, the amount of heat that moves and the distance it falls (change in temperature) determine the available power. However, later he realized that some of the heat is lost when it is converted to mechanical energy (work), which means it can't be a fluid like water (water isn't lost when falling water is used to drive a motor).
Mayer used data other people collected on heat capacities of air at constant pressure or constant volume to calculate the relationship between the energy defined as force x distance (like the modern unit joule) and energy defined by change in temperature of a substance (like the modern unit calorie, the energy needed to raise the temperature of 1g of water 1°C). Imagine heating a sample of air in a fixed volume container or in a chamber with a piston, so that it is always at atmospheric pressure. One sample does work when heated (by expanding against atmospheric pressure) and the other does not. The difference in heat required to get the same temperature change in the 2 containers must be equivalent to the work done by the system with the piston. Mayer argued that heat, work, and chemical energy are all interconvertible, meaning they are all energy in different forms.
Joule (for whom the unit joule is named) was an English beer-brewer
who did the studies mentioned earlier
that lead to the first law. You might have learned Joule's law in a
physics class, that heat produced by electricity, Q, is
Q ∝ I2R
where I is current and R is resistance. He compared heat produced
by electricity and heat produced by mechanical work (heating water
using a paddlewheel powered by a falling weight) and thus showed the
equivalence of mechanical work and heat. In other words, Joule and
Carnot had showed that heat can be used to generate work (like in a
powerplant) and work can be used to generate heat (like with the
cannon drills or paddlewheel). Kelvin combined these ideas and used
them to propose the Kelvin temperature scale (but the details of
that can wait until we study Carnot's discoveries in more detail).