So the big question comes down to rotating the cam. One way to do it would be to use a small electric motor. But if you did that, you would need to replace the batteries all the time, and that's no fun. Besides, you have a built-in power source: the running water that flows right through the sprinkler. You might as well use it in the same way that a hydro-electric dam uses water to spin its turbines.
If you cut open the body of the sprinkler, you can see that this is exactly how the sprinkler works. Inside there is a small turbine, or water wheel:
If you look down the tube where you attach the hose, you can see a small restrictor that allows some water to flow straight ahead and forces some water to shoot to the left. It is the water shooting to the left that spins the turbine:
To see the turbine in action, take a look at this video.