Here is a typical oscillating sprinkler that you might buy at any discount or home improvement store for a few dollars:
You attach the hose to a connector on the right-hand side (not shown). There is often a knob that lets you adjust the spray pattern (full, center, left or right):
Connected to the knob there is small arm that gets pushed and pulled by a heart-shaped cam. When the sprinkler is running, the cam rotates slowly -- at roughly 1 revolution per minute (rpm) -- this is what causes the arm to oscillate back and forth.
There is also the spray arm itself, which is a hollow aluminum tube with holes in it (on some sprinklers there are nozzles on this tube):
The spray arm has a ferrule and an O-ring seal on it, and it screws into the body of the sprinkler.
You can see that this is an incredibly simple device at its core. Water flows into the spray arm -- the aluminum tube -- and it sprays out through the holes or nozzles. The cam pushes the spray arm back and forth. Why does it have a heart-shaped cam instead of a simple little crankshaft? It's because a circular crankshaft would cause both ends of the spray pattern to get a lot more water than the center of the spray pattern. Think about a piston going up and down in an internal-combustion engine -- it is traveling slowest at each end of its travel, and fastest when it is in the center of the cylinder. The spray arm would have that same problem. The heart-shaped cam evens things out.