A Legal Briefing written for people who are being hassled by the police makes several good suggestions:
1. Don't consent to a search (except for a hand-pat to check for weapons) unless you are under arrest. Say "I don't consent."
2. Unless an officer specifically arrests you, don't give him your name or anything else. If he seems interested in detaining you, ask "Am I free to go?" Unless you are under arrest, you may leave quietly without identifying yourself.
3. If you are not free to go, then you may simply be "detained" while they decide whether or not to arrest you. Don't speak except to say "I'm going to remain silent. I would like to speak to a lawyer."
4. If you are arrested, you must give your name and show ID. Otherwise, remain silent except to ask for a lawyer.
I am a law-abiding citizen, so I have nothing to hide, but I have heard stories of people who somehow come into contact with the law and it could happen to me someday too. It's nice to remember your rights, even if you think you have nothing to hide.