When you're charged with a crime based upon a search of a vehicle after a traffic stop, one should always consider whether the police violated the 4th Amendment.
The 4th Amendment of the U.S. Constitution provides us all with a right to be secure against "unreasonable searches and seizures". Said another way, all searches and seizures conducted by government officials must be reasonable. If the search or seizure is unreasonable, then any evidence obtained by the police based upon the unreasonable search or seizure must be excluded.
In the traffic stop scenario, the first question is whether the officer violated the 4th Amendment by stopping or "seizing" the vehicle. A police officer can stop a vehicle whenever he or she observes a violation of the traffic law. So if you committed a traffic violation, an officer can stop your car. Period.
However, if the officer doesn't witness a traffic violation, then the officer may only stop a vehicle where he or she can point to "specific and articulable facts that, taken together with rational inferences derived from those facts, give rise to a reasonable suspicion that the individual has committed, is committing, or is about to commit a crime." This is known as an "investigatory stop" and a trial court is required to consider the "totality of the circumstances" in determining whether an investigatory stop is legal.
Assuming the stop was legal, the next issue is whether the officer violated the 4th Amendment by searching your car. Even if the officer was allowed to stop the car, he or she may still have violated your rights by searching the car.
As a general rule, the 4th Amendment requires police to have a warrant before they conduct any search. However, the police may search a vehicle without a warrant as long as the police have probable cause to believe the vehicle contains evidence of criminal activity. Therefore, they may only get into your vehicle if they have probable cause to search it or you give consent to the search.
If you are charged with a crime related to a search after a traffic stop, you should speak with a lawyer IMMEDIATELY regarding your 4th Amendment rights. Whether there is a violation usually determines the outcome of the case.
I hope this helps!