BackgroundKanamycin (KAN) residues in animal-derived foods continuously enter the human body, which will pose serious threats to human health such as hearing loss, nephrotoxicity and other complications. Therefore, to sensitively detect KAN residues by a reliable technology is extremely urgent in food quality and safety. Compared with traditional methods being limited by cost and complexity, photoelectrochemical (PEC) biosensors benefit from some merits such as rapid response, excellent sensitivity and good stability. In this study, the construction of a highly efficient PEC platform to realize KAN residues detection is discussed. ResultsHerein, a novel p-n heterojunction consisting of flower-like BiOI microspheres and graphite carbon nitride (g-C3N4) nanoflakes was developed to establish a PEC aptasensor for KAN detection at 0 V. The prepared g-C3N4/BiOI heterostructure showed not only significantly enhanced PEC activity due to the larger specific surface area but also greatly increased charge separation efficiency owing to the strong internal electric field. Meanwhile, using g-C3N4/BiOI as a highly efficient photoactive material for binding amine-functionalized aptamers to capture KAN, the photocurrent signals showed a ‘turn off’ mode to achieve the sensitive detection of KAN. The proposed PEC aptasensor exhibited linear response for KAN from 5 × 10−9 to 3 × 10−7 mol L−1 with a low detection limit of 1.31 × 10−9 mol L−1, and satisfactory recoveries (97.44–107.38 %) were obtained in real food samples analysis. SignificanceThis work presented a novel p-n heterojunction-based PEC aptasensor with strong selectivity and stability, rendering it allowed to detect KAN in animal-derived foods including milk, honey and pork. Additionally, the detection range satisfied the MRLs for KAN specified by the national standards, demonstrating the potential application for food analysis. The study provides a new insight into the development of efficient and practical biosensors for antibiotic residues detection.