A sensor includes a lower electrode layer facing a cavity, a piezoelectric layer located on the lower electrode layer, and an upper electrode layer located on the piezoelectric layer. The piezoelectric layer includes a first piezoelectric part and a second piezoelectric part. The first piezoelectric part includes a first material having piezoelectricity and at least partially overlays the cavity when viewed on a plane. The second piezoelectric part includes a second material having piezoelectricity and being different in at least one of a “g” constant and “d” constant from the first material and, when viewed on a plane, is located in a region different from an arrangement region of the first piezoelectric part and at least partially overlays the cavity.