Perpetual motion machines are machines that produce useful work indefinitely or produce more useful energy than they consume.
Such machines violate the first and second laws of thermodynamics – statements of conservation of energy and that heat flows from a hotter to a colder body respectively - and do not in fact exist. Many systems though can produce useful energy indefinitely – solar panels, wind turbines and wave powered electricity generators. These are not perpetual motion machines and do not violate either of the first two laws of thermodynamics. All of these power sources require inputs of energy from an external source, in the form of light, wind or wave, respectively, converting this into electrical energy. The energy produced by the machine is in each case, less than the energy supplied, but since the energy supplied is free and effectively infinite, many people are confused.
In fact any machine necessarily lose useful energy to friction or generates heat that is unavoidably lost to the surroundings. In practice, the useful energy from a machine is always less that the energy supplied.
Consider the machine above. It's inventor designed it to work in the following way. On one side of the wheel the hammers extend straight out, making a longer lever arm (the distance from the centre of the wheel to the hammer's head). On the opposite side of the wheel, the hammers lie close and make a short lever arm. Since the lever ratio is greater where the hammers stick out, it's unbalanced and makes the system want to tip, and thus the wheel to rotate. As it rotates around, the next hammer falls into place continuing the motion. This explanation ignores friction and that angular momentum of the system as a whole is gradually lost to friction, so the machine eventually comes to a stop.