Arrector Pili Muscle - This is a tiny muscle that attaches to the base of a hair follicle at one end and to dermal tissue on the other end. In order to generate heat when the body is cold, the arrector pili muscles contract all at once, causing the hair to "stand up straight" on the skin.
Hope this helped, credits go too google.