This work develops a novel photoelectrochemical sensor for the detection of carcinoembryonic antigen (CEA) based on the composite of UCNPs with semiconductors and conformational changes in the DNA structure. Firstly, SnS2, ZnIn2S4 and UCNPs were assembled on the surface of the ITO electrode. Then Au NPs were dropped, which could facilitate the coupling of CdSe NPs modified DNA1 via Au-S bond, giving an ITO/SnS2/ZnIn2S4/UCNPs/CdSe heterojunction structure. When irradiated with 980nm near-infrared (NIR) light, the UV-visible light emitted by the UCNPs could excite the nanocomposite, producing an enhanced photoelectric reaction. Subsequently, CEA aptamer and DNA2-modified SiO2 were added to form a Y-shaped DNA structure. At this time, the photocurrent was significantly reduced by the combination of the light-blocking effect of SiO2 and the departure of CdSe NPs from the electrode surface. When the target CEA was added, the recognition between CEA and the aptamer led to the collapse of the Y-shaped DNA structure, the restoration of hairpin DNA and the proximity of CdSe to the electrode. Accordingly, the photocurrent signals enhanced again. Under optimal experimental conditions, the detection limit as low as 0.3pgmL-1 was obtained with good selectivity, achieving a sensitive "on-off-on" photoelectrochemical sensor for CEA detection.