Magnesium alloys have demonstrated tremendous potential as bio-implants due to their superior biomedical properties. This study examines the influence of surface roughness on the electrodeposition of Hydroxyapatite (HA) coatings on AZ31B magnesium alloy samples. We investigated samples grit-blasted with quartz and alumina at various pressures and compared them with un-blasted samples to ensure a comprehensive analysis across different deposition times. Higher blasting pressure resulted in increased surface roughness. Overall, samples blasted with alumina exhibited greater surface roughness and thicker coatings. X-ray diffraction (XRD)analysis confirmed the presence of HA coatings. Scanning electron microscope (SEM) analysis revealed that HA coating thickness increased with longer deposition times. Open circuit potential (OCP) measurements indicated that alumina-blasted samples showed nearly complete coverage with a 10-minute HA deposition at 700 kPa (approximately − 0.336 V), with increased compactness and more positive OCP values observed with longer deposition times. Complete insulated coverage was achieved at 40 min, with OCP values of -0.075 V at 700 kPa and − 0.049 V at 1000 kPa. Statistical analysis using ANOVA demonstrated that both blasting pressure and deposition time significantly impact coating thickness, with blasting pressure having a primary effect on OCP. Higher OCP values indicated a 95% increase in corrosion resistance at a blasting pressure of 1000 kPa and a 40-minute deposition time for alumina-blasted samples. The Ca/P ratio (∼ 1.67) and XRD patterns consistently confirmed the HA phase.