A photoelectrochemical (PEC) sensor based on hierarchically porous Cu-BTC/g-C3N4 nanosheet (Cu-BTC/CN-NS, BTC = benzene-1,3,5-tricarboxylic acid) material was constructed for the first time. As a composite material, the hierarchically porous Cu-BTC can help to efficiently capture suitable pesticide molecules and accelerate signal transmission, while CN-NS possesses good optical performance. Under the irradiation of visible light, the Cu metal center can coordinate with the added glyphosate to form Cu-glyphosate complexes, leading to the increased steric hindrance of electron transfer and consequently resulted in an obvious decrease in photocurrent. Through this strategy, the constructed sensor can realize the detection of glyphosate from non-electroactive to electroactive. The results indicate that this photoelectrochemical sensor has a low detection limit of 1.3 × 10−13 mol L−1 and a wide detection range (1.0 × 10−12–1.0 × 10−8 mol L−1 and 1.0 × 10−8 ∼ 1.0 × 10−3 mol L−1). Furthermore, this Cu-BTC/CN-NS based sensor has the characteristics of short detection time and easy operation. It has great potential applications in photoelectrochemical analysis.