A hub motor, comprising: - a stationary motor shaft; - a rotatable hub casing; - a rotating seat that synchronously rotates with a crank chain wheel of an electric bicycle; - a rotating sleeve that synchronously rotates with the hub casing; - a ratchet mechanism of unidirectional transmission provided between the rotating seat and the rotating sleeve, wherein the rotating seat drives the rotating sleeve to rotate in the forward direction through the ratchet mechanism when the rotating seat rotates in a forward direction; wherein: - a magnet steel assembly and a Hall element assembly is provided within the hub casing; - the magnet steel assembly comprises a magnet steel holder that synchronously rotates with the rotating seat; several magnet steels annularly distributed around the motor shaft are provided on the magnet steel holder; - the magnet steel holder is an annular fixing plate, on which several circumferentially and evenly distributed magnet steel fixing holes for installing the magnet steels are provided; the annular fixing plate is movably sleeved onto the motor shaft and is fixedly connected to the hub casing; - the Hall element assembly comprises at least two Hall elements which are adjacently provided and close to the magnet steels; signal outputs of the Hall elements are connected to a controller of the hub motor; characterized in that - a motor stator is provided within the hub casing; the motor stator comprises a stator bracket which comprises a bracket inner ring and a bracket outer ring for fixing a stator core and a stator coil; a first through hole and a second through hole which are axially perforating are provided on the bracket inner ring; the bracket inner ring is fixed to the motor shaft in a sleeved way via the first through hole; the second through hole is provided oppositely to the magnet steel fixing holes; the Hall element assembly is fixed on the second through hole; - the first through hole communicates with the second through hole; and - the motor shaft is internally provided with an axially extending cable hole; signal output lines of the Hall elements are connected to the controller of the hub motor via the cable hole. - a stationary motor shaft; - a rotatable hub casing; - a rotating seat that synchronously rotates with a crank chain wheel of an electric bicycle; - a rotating sleeve that synchronously rotates with the hub casing; - a ratchet mechanism of unidirectional transmission provided between the rotating seat and the rotating sleeve, wherein the rotating seat drives the rotating sleeve to rotate in the forward direction through the ratchet mechanism when the rotating seat rotates in a forward direction; - a magnet steel assembly and a Hall element assembly is provided within the hub casing; - the magnet steel assembly comprises a magnet steel holder that synchronously rotates with the rotating seat; several magnet steels annularly distributed around the motor shaft are provided on the magnet steel holder; - the magnet steel holder is an annular fixing plate, on which several circumferentially and evenly distributed magnet steel fixing holes for installing the magnet steels are provided; the annular fixing plate is movably sleeved onto the motor shaft and is fixedly connected to the hub casing; - the Hall element assembly comprises at least two Hall elements which are adjacently provided and close to the magnet steels; signal outputs of the Hall elements are connected to a controller of the hub motor; characterized in that - a motor stator is provided within the hub casing; the motor stator comprises a stator bracket which comprises a bracket inner ring and a bracket outer ring for fixing a stator core and a stator coil; a first through hole and a second through hole which are axially perforating are provided on the bracket inner ring; the bracket inner ring is fixed to the motor shaft in a sleeved way via the first through hole; the second through hole is provided oppositely to the magnet steel fixing holes; the Hall element assembly is fixed on the second through hole; - the first through hole communicates with the second through hole; and - the motor shaft is internally provided with an axially extending cable hole; signal output lines of the Hall elements are connected to the controller of the hub motor via the cable hole.