
In the 4-stroke gasoline engine, the inlet and exhaust ports are opened and closed by valves. These valves need a system to control how they work. The valve is held in place by a valve guide, with a spring on its stem. A rocker arm is attached to a stationary shaft that allows the arm to pivot. The rocker arm compresses and releases the valve spring, so that the valve opens and closes.
The valves need a system to control how they work. This is done by using cams.
A cam is a lobe, on a shaft. It is specially shaped to open the valve, hold it open, and let it close. The cams control the valve action, but what drives the cams?
Cams are attached to a camshaft. In modern vehicles it's usually mounted over the cylinder head and is called an overhead camshaft.
Intake and exhaust lobes can be on the same shaft. Or there can be a shaft each for intake and exhaust.
Notice that in this design (right), there is no need for rocker arms. It's a much simpler arrangement. A camshaft can also be mounted in the engine block near the crankshaft. As the camshaft rotates motion is transferred through the pushrod to the rocker arm. It pivots and opens the valve.