To address the issues of missed and false detections caused by numerous tiny objects and complex background textures in printed circuit boards (PCBs), as well as the difficulty of embedding detection models into portable devices, this paper proposes an ultra-lightweight YOLOv8n defect detection method. Firstly, the method introduces an Uncertainty-driven Adaptive Training Sample Selection (UATSS) strategy during training to optimize model training and enhance detection accuracy. Secondly, it incorporates Details-Enhanced Convolution (DEConv) to improve the model's ability to extract detailed features of small PCB defects. Then, it employs a Sharing Lightweight Details-Enhanced Convolutional Detection Head (SLDECD) to replace the original Decoupled Head, reducing model complexity while enhancing network detection accuracy. Lastly, the Exponential Moving Average-Slide Loss (EMA-SlideLoss) function is introduced to provide more precise evaluation results during model training and enhance generalization capability. Comparative experiments on public PCB datasets demonstrate that the improved algorithm achieves an mAP of 97.6% and an accuracy of 99.6%, representing increases of 3.8% and 1.9%, respectively, compared to the original model. The model size is 4.1 MB, and the FPS reaches 144.1, meeting the requirements for portable embedded devices and real-time applications.