Our body responds to changes in the environment without even thinking of it. We term this reflex action. Here the peripheral nervous system (spinal cord) of the brain responds to changes and do the action with minimal time.
Role of our brain here is a learning experience from the event. Cerebrum receives the cause and action of the activity happened. It interprets the happening and stores the learned experience for faster future response.
Also, read:
What is the difference between a reflex and walking?