The actions you described involve two systems in the body: the nervous system and the muscular system.
-
Nervous System: When you step on the tack, the sensory receptors in your foot detect the pain and send signals through sensory neurons to your spinal cord and brain, which process the information and initiate a reflex action (jerking your foot away). This is part of the nervous system's response to a stimulus.
-
Muscular System: The movement to jerk your foot away and later to pick up the tack involves the muscular system. Muscles contract to facilitate these movements.
So in summary, the nervous system is responsible for processing the pain and reflex actions, while the muscular system is involved in the physical movements you make in response.