The invention provides a humidity sensor which is characterized by comprising a machine frame, a mobile unit, a weighing bench, an optical grating and a prism unit, wherein the mobile unit is arrangedon the machine frame and comprises a micrometer caliper and a scale plate, the weighing bench is arranged on the mobile unit and can be driven by the mobile unit to move up and down, the optical grating is arranged on the weighing bench, the prism unit comprises a clamping assembly arranged on the machine frame and a prism clamped by the clamping assembly, the prism unit is used for receiving terahertz optical and being coupled with the optical grating to generate a resonance peak, and a refractive index of the prism is larger than that of air. According to the humidity sensor disclosed by the invention, the situation that an absorption peak of vapor in a terahertz wave band right coincides with a resonance peak of a surface plasmon polariton generated by the optical grating under the terahertz attenuation total reflection action is utilized, so that a moisture content in air can be quickly measured in real time, flexibility is greatly improved, and a resolution ratio is higher. In addition, the humidity sensor has the advantages of simple structure, wide material taking and easiness in processing.