Animals integrate information from different sensory modalities, body parts, and time points to inform behavioral choice, but the relevant sensory comparisons and the underlying neural circuits are still largely unknown. We use the grooming behavior of Drosophila melanogaster as a model to investigate the sensory comparisons that govern a motor sequence. Flies perform grooming movements spontaneously, but when covered with dust, they clean their bodies following an anterior-to-posterior sequence. After investigating different sensory modalities that could detect dust, we focus on mechanosensory bristle neurons, whose optogenetic activation induces a similar sequence. Computational modeling predicts that higher sensory input strength to the head will cause anterior grooming to occur first. We test this prediction using an optogenetic competition assay whereby two targeted light beams independently activate mechanosensory bristle neurons on different body parts. We find that the initial choice of grooming movement is determined by the ratio of sensory inputs to different body parts. In dust-covered flies, sensory inputs change as a result of successful cleaning movements. Simulations from our model suggest that this change results in sequence progression. One possibility is that flies perform frequent comparisons between anterior and posterior sensory inputs, and the changing ratios drive different behavior choices. Alternatively, flies may track the temporal change in sensory input to a given body part to measure cleaning effectiveness. The first hypothesis is supported by our optogenetic competition experiments: iterative spatial comparisons of sensory inputs between body parts is essential for organizing grooming movements in sequence.