Herein, the Polyvinyl pyrrolidone (PVP)‐assisted CdS/PbI2 heterojunction UV–visible photodetector is constructed by the sol–gel spin coating method. The X‐ray diffraction, scanning electron microscopy, and energy dispersive spectrometer demonstrate the synthesis and successful complexation of PVP, CdS, and PbI2. The UV–visible absorption spectroscopy and UV photoelectron spectroscopy measurements of CdS and PbI2 are carried out to prove that the CdS and PbI2 form a type II heterojunction. Compared with pure CdS film photodetector, the CdS (PVP)/PbI2 heterojunction photodetector has self‐powered characteristics, and exhibits excellent photoconductivity in the UV–visible with higher switching ratios, detection rates, and faster response times of 1.1 × 105, 9.77 × 1011 Jones, and 20 ms, respectively, which has great potential in the field of UV–visible self‐powered photodetector.