We synthesized a CdS–rGO–C3N4 nanocomposite with enhanced photoelectrochemical (PEC) performance to construct a self-powered PEC aptasensor for sensitive and selective detection of PCB72.