If a police officer is talking to you, chances are, you’re already in trouble, whether you know it or not. If it’s something more than a simple traffic stop, the police are eventually going to 1) ask for consent to search you, or your vehicle, or your house, or your belongings, and 2) talk to you about the crime they suspect you’ve committed.
You can always refuse consent. Be nice about it, but be firm. When the police officer asks why, just tell them that you don’t consent to searches. Repeat ad nauseam. Go look up the explanatory videos on FlexYourRights.org for more info.
You can also refuse to talk to a police officer. Ask if you’re free to leave. If they say yes, then leave. If not, tell them you want an attorney before you are questioned any further.
Police can certainly punish you for refusing these constitutional rights. They can threaten to bring in a drug dog, or tell you if they find contraband, they’ll put you in jail instead of giving you a citation to appear out of custody at a later time. But by using your rights, you are stopping them from building a case against you.