Active sensation requires the convergence of external stimuli with representations of body movements. We used mouse behavior, electrophysiology and optogenetics to dissect the temporal interactions among whisker movement, neural activity and sensation of touch. We photostimulated layer 4 activity in single barrels in a closed loop with whisking. Mimicking touch-related neural activity caused illusory perception of an object at a particular location, but scrambling the timing of the spikes over one whisking cycle (tens of milliseconds) did not abolish the illusion, indicating that knowledge of instantaneous whisker position is unnecessary for discriminating object locations. The illusions were induced only during bouts of directed whisking, when mice expected touch, and in the relevant barrel. Reducing activity biased behavior, consistent with a spike count code for object detection at a particular location. Our results show that mice integrate coding of touch with movement over timescales of a whisking bout to produce perception of active touch.