We report a miniaturized spectrometer based on Hadamard transformation. The compact spectrometer utilizes a single-pixel photodetector and thus can operate at any wavelengths at relatively low cost. The spectrometer utilizes a MEMS-driven moving mask to encode the light intensity at its imaging slit, and the encoded light is then collected by a single-pixel detector. The light spectrum is recovered through an inverse Hadamard transform after a complete set of encoding is measured and recorded. The spectrometer is experimentally demonstrated with a spectral resolution better than 3 nm covering the full visible spectrum from 400 nm to 700 nm, and is capable of measuring over 200 spectra per second.