This paper puts forth a novel mobile fault detection algorithm for wireless sensor networks (WSNs) based on bacterial-inspired optimization. We introduce a bio-swarm intelligence approach to mobile fault detection in WSNs by using voltage values. At certain times, the sensor nodes in the clustered network send datapackets containing health-fitness information to cluster heads (CHs) selected by the proposed CH selection algorithm. A mobile sink (MS) collects the health status via data from all the nodes as they reach the intersection point of the CHs. After this stage, the data packets are analyzed by the MS, and hardware or software faults are detected by assessing the fitness values of the nodes. The faulty nodes are eventually discarded from the network, and recovery of the rest of the nodes in the network is satisfied. Inspired by the interaction of bacteria for feed collection, their response to chemicals, and their interaction and communication with one another, we bring an innovative approach to finding node failures or software faults in WSNs, and these failures are removed from the network to help its operation and to take measures to maintain the electrical structures. In fact, we adaptour algorithm to low energy harvesting electrical components as an example. We compare our novel algorithm with existing studies through extensive simulations in NS 2 environment based on fault detection accuracy, false alarm rate, and false positive rate criteria versus fault probability, number of nodes, and sink speed. Considering detection accuracy, the simulation results validate that our algorithm shows better performance as compared with others.