The main goal of this work is to measure rotation periods of the M-type dwarf stars being observed by the CARMENES exoplanet survey to help distinguish radial-velocity signals produced by magnetic activity from those produced by exoplanets. Rotation periods are also fundamental for a detailed study of the relation between activity and rotation in late-type stars. We look for significant periodic signals in 622 photometric time series of 337 bright, nearby M dwarfs obtained by long-time baseline, automated surveys (MEarth, ASAS, SuperWASP, NSVS, Catalina, ASAS-SN, K2, and HATNet) and, for 20 stars, obtained by us with four 0.2-0.8m telescopes at high geographical latitudes. We present 142 rotation periods (73 new) from 0.12d to 133d and ten long-term activity cycles (six new) from 3.0a to 11.5a. We compare our determinations with those in the existing literature, investigate the distribution of Prot in the CARMENES input catalogue, the amplitude of photometric variability, and their relation to vsini and pEW(H{alpha}), and identify three very active stars with new rotation periods between 0.34d and 23.6d.