When the whiskers touch an object this causes them to vibrate and the vibration pattern is picked up by sensitive cells in the hair follicle at the base of the whisker. These patterns are turned into an electrical signal which is sent to the brain, enabling the mammal to make instant decisions about its environment to help it move around or catch prey. The whiskers have another advantage over some other forms of tactile touch. Whiskers themselves are easily replaceable since the sensory cells are at the base of the whisker, not the top, unlike our fingers for example, which are more easily damaged and hard to replace.
[Shrew whiskers inspire ground-breaking robot design via core77]