A generator converts mechanical energy into electrical energy, while a motor does the opposite, it converts electrical energy into mechanical energy. Both devices work on electromagnetic induction, i.e. emf is induced in the coil by a changing magnetic field.