Moisture content testing of agricultural products is critical for quality control, processing efficiency and storage management. Testing foxtail millet moisture content ensures stable foxtail millet quality and helps farmers determine the best time to harvest. A differential capacitance moisture content detection device was designed based on STM32 and PCAP01 capacitance digital converter chip. The capacitance method combined with the back-propagation(BP) algorithm and the extreme learning machine(ELM) algorithm was chosen to construct an analytical model for foxtail millet moisture content, temperature, and volume duty cycle. This work performs capacitance measurements on foxtail millet with different moisture contents, temperatures, and proportions of the measured substance occupying the detection area (that is, the volumetric duty cycle). On this foundation, the sparrow search algorithm (SSA) is used to optimize the BP and ELM models. However, SSA may encounter problems such as falling into local optimization solutions due to the reduction of population diversity in the late iterations. As a consequence, Logistic algorithm is introduced to optimize SSA, making it more appropriate for solving specific problems. Upon comparative analysis, the model predicted using the Logistic-SSA-ELM algorithm was more accurate. The results indicate that the predicted values of prediction set coefficient of determination (RP), prediction set root mean square error (RMSEP) and prediction set ratio performance deviation (RPDP) were 0.7016, 3.7150 and 1.4035, respectively. This algorithm has excellent prediction performance and can be used as a model for detection of foxtail millet moisture content. In view of the important role of foxtail millet moisture content detection in acquisition and storage, it is particularly important to study a nondestructive and fast online real-time detection method. The designed capacitive sensor with differential structure has well stabilization and high accuracy, which can be further studied in depth and gradually move towards the general trend of agricultural development of smart agriculture and precision agriculture.