Combining with a pathogen-associated molecular pattern (PAMP), a structure conserved among microbial species, or damage-associated molecular pattern (DAMP), an endogenous molecule released from damaged cells), to initiate a change in cell activity.