The device (100) comprises a substrate (10) of a semiconductor material with a first and an opposite second surface (1,2) and a microelectromechanical (MEMS) element (50) which is provided with a fixed and a movable electrode (52, 51) that is present in a cavity (30). One of the electrodes (51,52) is defined in the substrate (10). The movable electrode (51) is movable towards and from the fixed electrode (52) between a first gapped position and a second position. The cavity (30) is opened through holes (18) in the substrate (10) that are exposed on the second surface (2) of the substrate (10). The cavity (30) has a height that is defined by at least one post (15) in the substrate (10), which laterally substantially surrounds the cavity (15).