An optical sensor for detecting objects within a monitoring area, having sensor components and electronic components which are arranged in at least one housing (2a or 2b) in which at least one printed circuit board accommodating sensor components and/or electronic components is mounted, wherein the printed circuit board is mounted without play in grooves arranged in the housing (2a or 2b) with intermediate storage of an elastic material, and wherein the elastic material is in the form of elastic elements mounted in the grooves and/or the printed circuit board, characterised in that at least one elastic element in the form of a rail element is attached to each edge of the printed circuit board which can be inserted into a groove, wherein the edges of the printed circuit board each extend parallel to one another along a straight line, wherein a respective rail element is arranged in a longitudinal end region of the printed circuit board at the edges thereof, wherein the longitudinal axes of the rail elements run inclined to the edges of the printed circuit board, the printed circuit board being inclined for insertion of the printed circuit board into the region of the grooves, so that the longitudinal axes of the rail elements guided in the grooves run parallel to the longitudinal axes of the grooves, and wherein the printed circuit board is aligned in a plane spanned by the grooves in order to fix it, whereby the position of the printed circuit board is secured by tilting the rail elements in the grooves, or in that the width of the printed circuit board tapers continuously from its centre towards the longitudinal ends, the printed circuit board having two sections which are symmetrical with respect to the central plane and taper conically towards its longitudinal end, a rail element being present on each conical section of the printed circuit board, wherein the two rail elements are arranged at opposite edges of the printed circuit board, the printed circuit board being inserted into the grooves in a first lateral tilted position of the printed circuit board, in which the edge regions of the printed circuit board are guided in the grooves without rail elements, and wherein the printed circuit board is fixed in position in the grooves in that the printed circuit board is tilted laterally into a second tilted position in which the rail elements are in engagement with the grooves. wherein the printed circuit board is mounted without play in grooves arranged in the housing (2a or 2b) with intermediate storage of an elastic material, and wherein the elastic material is in the form of elastic elements mounted in the grooves and/or the printed circuit board, characterised in that at least one elastic element in the form of a rail element is attached to each edge of the printed circuit board which can be inserted into a groove, wherein the edges of the printed circuit board each extend parallel to one another along a straight line, wherein a respective rail element is arranged in a longitudinal end region of the printed circuit board at the edges thereof, wherein the longitudinal axes of the rail elements run inclined to the edges of the printed circuit board, the printed circuit board being inclined for insertion of the printed circuit board into the region of the grooves, so that the longitudinal axes of the rail elements guided in the grooves run parallel to the longitudinal axes of the grooves, and wherein the printed circuit board is aligned in a plane spanned by the grooves in order to fix it, whereby the position of the printed circuit board is secured by tilting the rail elements in the grooves, or in that the width of the printed circuit board tapers continuously from its centre towards the longitudinal ends, the printed circuit board having two sections which are symmetrical with respect to the central plane and taper conically towards its longitudinal end, a rail element being present on each conical section of the printed circuit board, wherein the two rail elements are arranged at opposite edges of the printed circuit board, the printed circuit board being inserted into the grooves in a first lateral tilted position of the printed circuit board, in which the edge regions of the printed circuit board are guided in the grooves without rail elements, and wherein the printed circuit board is fixed in position in the grooves in that the printed circuit board is tilted laterally into a second tilted position in which the rail elements are in engagement with the grooves.