Atrazine (ATZ), as a widely used herbicide, is easy to cause water pollution and serious harm to human health because of its high mobility and long residue period. Herein, a photoelectrochemical (PEC) aptasensor based on graphitic carbon nitride (g-C3N4) loaded by CoN nanoparticles as the electron acceptor (CoN/g-C3N4) was proposed for sensitive detection of ATZ. CoN/g-C3N4 composites were synthesized by using a straightforward hydrothermal and ammonia calcination process. CoN can act as the electron acceptor to promote the transfer of photogenerated charge on the electron donor (g-C3N4). The strong electron-absorbing capacity and wide visible light absorption range of CoN nanoparticles are conducive to the extraction of photogenerated charge. The photocurrent response of g-C3N4 under visible light irradiation was remarkably improved when CoN nanoparticles were introduced. Based on the excellent PEC performance of CoN/g-C3N4, a PEC aptasensor for detecting ATZ was successfully constructed. The linear response range of the sensor to ATZ was to be from 1.0 × 10−4 to 10 fM, and the detection limit was up to 3.3 × 10−5 fM. This aptasensor had excellent stability, selectivity, and excellent anti-jamming capability against real water samples. In view of specific recognition and excellent sensing performance, this aptasenor can be used as a practical technology for selective and sensitive detection of ATZ in the aquatic environment.