In this study, we designed and synthesized a new class of donor–acceptor conjugated polymers containing the polyaniline-quinoxaline [Acenaptho [1, 2 -b] quinoxalin-9-amine] (PAni-QUA) composite, and we subsequently utilized it as an electrochemical sensor to detect Hg2+ and Pb2+ ions with good selectivity and sensitivity. Energy dispersive X-ray analysis spectroscopy (EDAX), scanning electron microscopy (SEM), Fourier transform infrared spectroscopy (FT-IR), and UV–Vis spectroscopy (UV–Vis) were employed to analyze the structural and morphological characteristics of the resulting composite. The electrochemical characteristics of the electrode modifiers were analyzed using cyclic voltammetry (CV) and electrochemical impedance spectroscopy (EIS). Several sensitivity-influencing factors, including chemical and electrochemical parameters like pH and the impact of the supporting electrolyte medium, were also identified to improve the efficiency of the developed sensor. In the presence of different hazardous metal ion species, the interference ability of the proposed sensor was also examined. They were also used to conduct individual and simultaneous sensing studies of various metal ions in different supportive electrolyte media utilizing the differential pulse voltammetry technique (DPV). The PAni-QUA composite modified GCE sensor shows remarkable selectivity and sensitivity towards Hg2+ and Pb2+ ions over the other heavy metal ions in 1 to 20 µM ranges, respectively. The detection limits (3σ/m) were 1.28 nM and 5.91 nM for Hg2+ and Pb2+ ions. Density Functional Theory (DFT) was used in the present study to accomplish the adsorption mechanism of the suggested sensors. The DFT calculation demonstrated that the PAni-QUA composite was formed with a lower band gap energy than QUA and DD PAni. These results showed that the suggested sensor (PAni-QUA) had the lowest detection limit in the acetate buffer medium compared to the specified electrolyte media. Based on these findings, it is possible to use this technology to identify harmful metal ions (Hg2+ and Pb2+) with high sensitivity in real water samples.