How do nipples get hard?

nipples always get hard in these conditions

1. Arousal

2. during sex

3. During pregnancy

4. During breast feeding

5. If have any infection or inflammation.