An optical encoder comprising: a light source; a scale configured to be irradiated by the light source and having a fine pitch pattern and a coarse pitch pattern in a measuring direction in one track; a photo detector array comprising a plurality of photo detectors, wherein the detector resolution can be switched to detect either the fine pitch pattern or the coarse pitch pattern and detect transmitting light or reflected light from the scale, the transmitting light and the reflected light being emitted from the light source; a signal processing means including a first initial-stage amplifier means (34, 35, 36, 37) configured to generate a position detection signal from the photo detector array; and a control means configured to use an output signal from the first initial-stage amplifier means (34, 35, 36, 37) to control a light amount variation of the light source, wherein the optical encoder is configured to operate in either one of two detection modes: to operate in a high resolution detection mode by switching outputs of the photodetectors to selectively connect photodetectors to the first initial-stage amplifier means (34, 35, 36, 37) so as to form a photo detector array having a first detection pitch in the measuring direction to detect the fine pitch pattern or to operate in a low resolution detection mode by switching outputs of the photodetectors to selectively connect photodetectors to the first initial-stage amplifier means (34, 35, 36, 37) so as to form a photo detector array having a second detection pitch in the measuring direction to detect the coarse pitch pattern, the optical encoder includes a second initial-stage amplifier means to which an output of an unused photo detector is inputted when there is the unused photo detector which is not used to detect position in one of the high resolution detection mode and the low resolution detection mode, and the control means is configured to control the light amount variation of the light source on the basis of a sum signal of output signals from the first initial-stage amplifier means (34, 35, 36, 37) and the second initial-stage amplifier means when there is the unused photo detector. a light source; a scale configured to be irradiated by the light source and having a fine pitch pattern and a coarse pitch pattern in a measuring direction in one track; a photo detector array comprising a plurality of photo detectors, wherein the detector resolution can be switched to detect either the fine pitch pattern or the coarse pitch pattern and detect transmitting light or reflected light from the scale, the transmitting light and the reflected light being emitted from the light source; a signal processing means including a first initial-stage amplifier means (34, 35, 36, 37) configured to generate a position detection signal from the photo detector array; and a control means configured to use an output signal from the first initial-stage amplifier means (34, 35, 36, 37) to control a light amount variation of the light source, wherein the optical encoder is configured to operate in either one of two detection modes: to operate in a high resolution detection mode by switching outputs of the photodetectors to selectively connect photodetectors to the first initial-stage amplifier means (34, 35, 36, 37) so as to form a photo detector array having a first detection pitch in the measuring direction to detect the fine pitch pattern or to operate in a low resolution detection mode by switching outputs of the photodetectors to selectively connect photodetectors to the first initial-stage amplifier means (34, 35, 36, 37) so as to form a photo detector array having a second detection pitch in the measuring direction to detect the coarse pitch pattern, the optical encoder includes a second initial-stage amplifier means to which an output of an unused photo detector is inputted when there is the unused photo detector which is not used to detect position in one of the high resolution detection mode and the low resolution detection mode, and the control means is configured to control the light amount variation of the light source on the basis of a sum signal of output signals from the first initial-stage amplifier means (34, 35, 36, 37) and the second initial-stage amplifier means when there is the unused photo detector.