Boron (a metalloid) has been chosen as the doping agent in the titanium dioxide structure via in situ anodizing method in this work. FE-SEM, XPS, Raman spectroscopy, XRD, EDX and UV–visible techniques were used to investigate the morphology, structure and optical properties of the samples prepared. XPS and UV–visible techniques were used to confirm the presence of boron in the nanotubes and the reduction in band gap, respectively. Afterward, the impact of the concentration of the doping agent on the photoelectrocatalytic and anticorrosion properties of the nanotubes was studied through different electrochemical techniques such as linear sweep voltammetry, chronoamperometry, open-circuit potential and Tafel under visible light. Better photocatalytic performance and anticorrosion properties are shown by nanotubes modified by boron compared with bare titanium dioxide nanotubes, according to the results. The photo-response increases dramatically as boric acid concentration in anodizing electrolyte is increased from samples BT1 to BT10 and slowly decreases for samples BT10-BT25. The best photoelectrocatalytic performance in photoelectrochemical water splitting studies was shown by samples BT10 and BT15. Ultimately, the photo-generated cathodic protection of 403 stainless steel (403SS) has been studied in a corrosion cell using a 3.5% NaCl solution under visible light by the photocatalysts prepared. The photocatalytic activity of TiO2 under visible light illumination was enhanced by doping of boron, based on the results.