A sensor may include a light source, a light detector, and a housing. The housing may have a first upper side and extend from the first upper side, a first cavity and a second cavity. The light detector is arranged in the first cavity. The light source is arranged in the second cavity. A strut may be arranged between the first cavity and the second cavity and is made from a material that absorbs or reflects light. A first cover may be mounted above the first cavity and comprises a deflection region and a plane of incidence. The deflection region is designed such that 80% of the light which is incident in the deflection region on the plane of incidence of the first cover from a predetermined direction and which is incident on the light detector, is directed away from the light detector based on an optical element.