Answer:
That is because of Receptors. Receptors are groups of specialised cells. They detect a change in the environment stimulus. In the nervous system this leads to an electrical impulse being made in response to the stimulus.
Hope this helped
All the best !!