Aiming at the problems of low accuracy and slow detection rate of existing target detection algorithms for PCB defect detection, and too many parameters of algorithm model leading to the inability to deploy on mobile terminals, a PCB defect detection algorithm based on MSD-YOLOv5 is proposed.Firstly, to ensure both detection accuracy and speed while reducing the model's size,we combine the lightweight MobileNet-v3 network with the CSPDarknet53 network.Further,the attention mechanism is introduced to highlight the important feature channels and weaken the less useful ones, so as to improve the feature extraction ability of the network. Finally, the coupling detection head is replaced with a decoupling detection head, and the defect location information and category information on the PCB are extracted and learned respectively, which solves the problem of highly coupling of different information feature distributions and enhances the generalization ability of the model.We conduct experiments on a publicly available PCB defect dataset from Peking University using this algorithm.The results show that the proposed method reduces the parameters of YOLOv5 model by 46% and improves the detection accuracy by 3.34%.