Engines that make their power with pistons usually need a way of converting back-and-forth (reciprocating) motion into round-and-round (rotational) motion—a way of driving a wheel, in other words. Most engines use cranks to do this. A crank is simply an off-center connection that provides energy to (or takes energy from) a rotating wheel. As the crank pushes back and forth, the wheel rotates (or vice-versa). In this example, as the red wheel rotates, the green crank pushes the black and blue connecting rods back and forth, converting the wheel's rotary motion into reciprocal motion. So the red wheel moves round, but the blue rod moves back and forth.
The same mechanism could be used the opposite way to drive the wheel from a piston. You'd just hitch the blue rod up to the piston so that as it moved in and out of its cylinder, the red wheel would go round and round. Steam engine wheels are driven exactly like this.
Cams generally do the opposite job to cranks: they turn rotary motion into reciprocating motion. Whatever you need to move up and down (or back and forth) rests on top of an oval wheel, sometimes mounted off-center (the cam). As the cam rotates, the object it supports rises up and down. In this example, you can see the blue box rises and falls as the green cam turns round and round. But most of the time the box just sits there, motionless, with the cam slowly spinning beneath it. If you look closely at the way I've drawn the cam, you can see the secret of how it works. Three "quarters" of it is like a circle, so anything resting on it for three quarters of the time will neither rise nor fall, but stay motionless. The other quarter stretches out into an ellipse shape and that's the part that lifts and lowers every time it reaches the top.
Cranks in action!
It's all very well to talk about things in theory with little animated graphics, but it's much more interesting to see how these things work in actual machines. The following selection of photos shows you some examples of cranks working hard in real life. I've not found any good pictures of cams, but I'll keep looking...
Car and boat engines have multiple cylinders that turn a single drive shaft, called the crankshaft. Each cylinder fires at a slightly different time so, at any given moment, there's always at least one cylinder adding power and driving the vehicle along. The cylinders are attached to the crankshaft by rods that connect to the piston rods inside the cylinders.
Photo: The shiny crankshaft from a brand new marine engine. Picture by Marco Bernardini published on Flickr in 2009 under a Creative Commons Licence.