A motor with a power generating function is provided to increase a generated power by delivering a magnetic force of a drum magnet to inner and outer electromagnets. An inner electromagnet(3) is arranged on an outer periphery of a rotation shaft(2). An outer electromagnet(5) is arranged on a main body(4). A drum magnet(6) includes a permanent magnet, which is fixed between the inner and outer electromagnets. A pair of holes are formed on a mask disk(8), which is fixed on one side of the rotation shaft. An optical sensor(8) is arranged around a rotation radius of the hole on the body, on which the mask disk is formed. The light from a light source is applied through the hole. A controller(11) applies a controlled current on the inner and outer electromagnets according to the detected result from the optical sensor, such that the drum magnet is pressurized.