They can smell the difference as our hormones start to change. Some pets don't care - at least until they feel you're vulnerable. Some pets think they need to take care of you right away. My boxer dog started being extra clingy with me before I even thought to test for pregnancy (as this pregnancy was a surprise). He used to sleep in the hallway at night so he could check in on my kids throughout the middle of the night, but one day, my chocolate lab started sleeping in the kids' room (I guess to keep an eye on them), and my boxer started snuggling with me in my bed.
This is my third pregnancy since adopting my boxer, and he knew right at implantation every time. He gets more and more protective of me as the pregnancy goes on. I know when my hormones start to change near the end because he will no leave my side for more than a few minutes, and if he goes outside to pee with someone else, he will come rushing in to make sure I'm still okay. Haha. Poor dog stresses himself out trying to nurse me when I'm pregnant.
My dogs also protect the babies, but that just means sleeping beside their cribs or peeking in on them frequently. Some companies make cat nets to keep cats out of the crib if necessary, but they're only safe until your baby can stand up.