a sensor for detecting a physical variable , including : — a sensor element for outputting an electrical signal dependent on the physical variable , — a substrate carrying the sensor element , — a printed circuit board , conducting the electrical signal , on the substrate , and — an embedding compound , in which the sensor element is completely embedded and the printed circuit board is at least partly embedded , — wherein at least one compensation element is embodied in the embedding compound , by which compensation element a mechanical stress caused by an element of the sensor at least partly embedded in the embedding compound is counteracted .