Soil total nitrogen (STN) serves as a critical indicator for agricultural productivity. Rapid STN detection is crucial for nutrient monitoring in farmland and for guiding precision fertilization. Traditional near-infrared spectroscopy-based STN detectors necessitate darkrooms or subterranean settings to negate ambient light interference, restricting their practical use. This study develops a handheld rapid STN detector employing phase-locked amplification technology to address this issue. The device comprises optical, circuit, and control units. The optical unit features a ring-shaped split fiber structure to mitigate soil surface irregularities’ effects on the signal, with a central InGaAs photodiode for signal reception. Eight wavelengths (970 nm, 1050 nm, 1085 nm, 1200 nm, 1300 nm, 1450 nm, 1550 nm, and 1600 nm) are selected for the light sources through an information theory optimized genetic algorithm. The circuit unit employs direct digital synthesis and operational amplifiers for light signal generation and modulation. Reflected soil light signals are demodulated using an InGaAs photodiode and a phase-locked amplifier, effectively filtering ambient light noise. The control unit integrates an STM32F103C8T6 microcontroller and a Raspberry Pi 4B. The STM32 microcontroller manages signal generation, channel selection, frequency control, A/D conversion, and display, while the Raspberry Pi handles data processing, uploading, and transmission. A BP neural network model optimized by genetic algorithms is embedded for real-time STN data acquisition. Cloud-based data storage and visualization are facilitated through the Alibaba Cloud IoT platform. Performance testing reveals the device’s stability and interference resistance, with a standard deviation of electrical signal under varying light conditions below 3 mV. Compared to commercial spectrometers, the correlation coefficient (r) for reflectance data at eight wavebands exceeds 0.9. Accuracy testing shows an R2 above 0.8 and an RMSE of 0.30 g/kg when comparing detector-obtained STN values with standard chemical methods. These results demonstrate the detector’s efficacy in ambient light isolation, stability, and accuracy in agricultural settings, offering technical support for variable fertilization in precision farming.