An optical sensor, comprising: a sensor assembly that includes a circuit board having a light source, a light detector, and one or more locating elements on the circuit board, and a light guidance assembly having a light pipe for guiding light from the light source and a lens for guiding light to the light detector, an enclosure having a housing and a lower cassette that cooperate to enclose the sensor assembly, the lower cassette having an internal recess for supporting lower portions of the light pipe and the lens, and an upper cassette interposed between the lower cassette and the circuit board, the upper cassette having one or more locating elements that cooperate with corresponding locating elements on the circuit board to locate the upper cassette relative to the circuit board, the locating elements on the circuit board and on the upper cassette form mechanical constraints that cooperate to align and to maintain alignment of the light source and the light detector and to secure the upper cassette to the circuit board via the corresponding locating elements on the circuit board and the upper cassette, the upper cassette having one or more alignment features that support upper portions of the light pipe and the lens in alignment with the light source and the light detector, respectively, the lower cassette having an interior receptacle for receipt of the upper cassette, where the locating element in the circuit board includes a socket, and the locating element in the upper cassette includes a pin that mates with the socket in the circuit board, and after adjustment to ensure that the light source is aligned, the pins being heat staked to secure the upper cassette to the circuit board. a sensor assembly that includes a circuit board having a light source, a light detector, and one or more locating elements on the circuit board, and a light guidance assembly having a light pipe for guiding light from the light source and a lens for guiding light to the light detector, an enclosure having a housing and a lower cassette that cooperate to enclose the sensor assembly, the lower cassette having an internal recess for supporting lower portions of the light pipe and the lens, and an upper cassette interposed between the lower cassette and the circuit board, the upper cassette having one or more locating elements that cooperate with corresponding locating elements on the circuit board to locate the upper cassette relative to the circuit board, the locating elements on the circuit board and on the upper cassette form mechanical constraints that cooperate to align and to maintain alignment of the light source and the light detector and to secure the upper cassette to the circuit board via the corresponding locating elements on the circuit board and the upper cassette, the upper cassette having one or more alignment features that support upper portions of the light pipe and the lens in alignment with the light source and the light detector, respectively, the lower cassette having an interior receptacle for receipt of the upper cassette, where the locating element in the circuit board includes a socket, and the locating element in the upper cassette includes a pin that mates with the socket in the circuit board, and after adjustment to ensure that the light source is aligned, the pins being heat staked to secure the upper cassette to the circuit board.