Let’s look at what each does well and doesn’t do well.
Pistols are handy to have on you and are good for moving about and performing other tasks where a free hand is needed, such as opening open doors, leading other people to safety and/or holding a flashlight. But they’re kinda lacking in the firepower department compared to a long gun.
An AR-15 makes a dandy home defensive firearm, but be warned: They are LOUD in enclosed spaces. If it’s legal to do so where you live, consider buying a suppressor, elsewise, some active hearing protection for you and your loved ones might not be a bad idea if you’re thinking about an AR-15 for home defense.