The 4th Amendment to the U.S. Constitution (and similar provisions of state constitutions) limits the power of police with respect to searches and seizures. In other words, this constitutional provision permits police to stop a person or search in someone's personal property only when there's adequate evidence of criminal activity.
The 4th Amendment's protections also apply to traffic stops. However, the rules that apply to vehicles are a little different than those for other types of searches and seizure. Here are some basics about the 4th Amendment rights of drivers.
Basically, the 4th Amendment aims to prevent unwarranted government intrusions into the lives of law-abiding citizens going about their business. So, in the context of traffic stops, the 4th Amendment generally requires police to have evidence of wrongdoing prior to pulling a vehicle over. In other words, the officer needs to have a reasonable basis to believe the driver or a passenger has broken the law.
In general, any traffic violation is sufficient to justify a traffic stop. However, in some states, certain minor violations (like seat belt and distracted driving offenses) are considered "secondary offenses." An officer can't pull a vehicle over for a secondary violation but can write a ticket for a secondary violation if there's another legitimate reason (like speeding, for instance) for the stop.
When an officer has a valid reason for initially stopping a vehicle, it's sometimes described as being "reasonable at its inception."
In many areas, police occasionally set up DUI checkpoints. At these checkpoints, police stop every vehicle that comes down the roadway with no evidence that anyone in the vehicle has broken the law. Without evidence of wrongdoing, it would seem that stopping vehicles at DUI checkpoints would violate the 4th Amendment.
Lots of defense attorneys were of this opinion, and the issue went all the way to the U.S. Supreme Court. Ultimately, the Supreme Court carved out an exception to the general rule for DUI checkpoints. In other cases, the Supreme Court also approved checkpoints for other purposes such as immigration compliance. Basically, the Supreme Court found that the interest of the government in enforcing certain laws (like immigration and DUI laws) outweighs the inconvenience to drivers.
Even if a traffic stop is reasonable at its inception, police aren't allowed to turn a legal traffic stop into an all-day affair. Basically, the rule is that an officer can't extend a traffic stop beyond the time reasonably necessary to complete the stop and write the ticket.
For example, suppose an officer stops a driver for speeding and issues a ticket. The officer then calls in a K-9 unit to sniff for drugs. The officer has a hunch but doesn't have any evidence that drugs might be in the car. Under these circumstances, it would be unlawful for the officer to make the driver wait for the K-9 unit to show up; the traffic stop for the speeding violation is complete, and the officer has no reasonable basis related to drugs to extend the stop for any longer.
If you've been arrested for any crime, it's a good idea to talk to a knowledgeable attorney as soon as possible. Search and seizure law is complicated and differs somewhat by state. A qualified attorney can tell you how the law applies to the facts of your case.