If the pungent aroma of weed is wafting from your ride, South Florida cops usually have a green light to search your car.

But with medical marijuana now allowed in Florida, along with some production of the similar-smelling hemp plant, a Miami man is challenging whether cops had the legal right to search his truck based on odor alone.

The novel defense is being employed by Victor Chavez, who was found with a stash of marijuana hidden his truck in Southwest Miami-Dade last year. His lawyer says cops violated his constitutional right against an unlawful search and seizure.

“The legalization of marijuana for a rapidly growing number of Floridians and businesses means that marijuana odor, in and of itself, is no longer an indication of criminality in Florida,” Assistant Miami-Dade Public Defender Fan Li wrote in his motion.

The legal fight comes as voters in states across the country have relaxed marijuana laws and Florida lawmakers appear ready to accept smokable medical marijuana. Miami-Dade Judge Alan Fine will consider Chavez’s request at a hearing next month.

But Chavez, 24, may have an uphill battle. Supreme courts in states such as Arizona and Washington have ruled that the smell of the herb is enough “probable cause” for cops to search a car, regardless of whether medical marijuana is legal.

“Marijuana possession and use in public and vehicles has not been decriminalized in Florida, therefore the odor of marijuana remains evidence of a crime and it gives probable cause to conduct a search,” Miami-Dade prosecutor Jessica Underwood wrote in her response.

States began approving medical marijuana laws in the mid-1990s, and today 33 have approved programs. An additional 10 states have ushered in recreational marijuana, even though federal law still forbids the drug.

Detecting the smell of marijuana, particularly around cars, has long been a powerful tool for law enforcement.

“In most states now, there is marijuana allowed for a lawful purpose. That just makes ‘probable cause’ much more complicated,” said Sam Kamin, a professor of marijuana law and policy at the University of Denver.

Florida voters in 2016 overwhelmingly approved a constitutional amendment to broaden the use of medical marijuana. But lawmakers limited access to the drug to pills, oils, edibles and vaping — not smoking. New Gov. Ron DeSantis, however, has urged the Legislature to allow the smoking of medical marijuana, and elected leaders appear poised to soon change the law.

Issues of medical marijuana have popped up sporadically in South Florida criminal courts.

In 2015, a Miami-Dade man claimed he had an illegal indoor grow house only to help his cancer-stricken wife. He lost at trial. Also that year, a Broward jury acquitted a Hollywood manwho said he was growing marijuana to treat his crippling anxiety.

In November 2017, despite objections from prosecutors, a Miami-Dade judge allowed a convicted killer with schizophrenia to use medical marijuana while on probation.

Legal fights over whether the smell of marijuana is enough to allow cops to search someone are not unusual for states with fledgling legalization programs. That was the case in Washington, one of the first states to legalize medical marijuana in the 1990s.

“Back in the early days, when medical marijuana laws were not as well recognized, a lot of lawyers raised these claims,” said Todd Maybrown, a Seattle lawyer who won an early case on the issue.

But in 2010, the Washington Supreme Court ruled that officers in Stevens County had probable cause to search the home of a man who claimed he qualified for medical marijuana, and had an indoor operation inside his house.

Even for states that have approved marijuana for recreational uses, what constitutes probable cause is not settled.

The Colorado Supreme Court is currently weighing whether police lawfully deployed a drug-sniffing dog, trained to detect marijuana, on a car in which methamphetamine was found.

“We passed a recreational law seven years ago and we’re still hashing it out,” said Kamin, the University of Denver law professor.

In the Miami-Dade case, Chavez isn’t claiming to have a valid medical-marijuana card, but he says the search was still illegal.

Chavez is charged with possession of cannabis with intent to sell or deliver, and possession of cannabis over 20 grams. He is also charged with possession of cocaine.

He was arrested on May 31, 2018, after a police sergeant saw his pickup truck parked in Southwest Miami-Dade and “obstructing the roadway.”

About half-an-hour later, two other officers saw the same truck parked on the other side of the street, except Chavez was inside. He “began to fidget, put his head down” and tried to drive away, police said.

That’s when Miami-Dade police officers Jacqueline Diaz and Christine Marte “could smell a strong odor of marijuana coming from the truck.”

On June 28, 2016, Surterra Therapeutics Cultivation Manager Wes Conner displays the fully grown flower of one of their marijuana plants at their North Florida facility, on the outskirts of Tallahassee. [Associated Press file]

They ordered Chavez out of the truck and found a small baggie of cocaine in his pocket — and an eight-gallon Ziplock bag stuffed with marijuana inside a checkered book bag.

His lawyer, Li, is asking the judge to suppress the results of the search, which would essentially doom the prosecution’s case.

For one, Li says, the search was illegal because Florida has authorized a pilot project examining the production of hemp, a related plant that does not have the same powerful concentration of THC, the active chemical that gives users a high. Hemp can be used as an industrial product in clothing, shoes and even insulation.

No rule restricts how hemp can be transported — and the plant smell is identical to cannabis, Li wrote.

And as for medical marijuana, enough people are approved to use medical marijuana — over 170,000 as of January — that cops cannot say that smell alone is evidence of a crime, the defense said.

Chavez, however, was not one of those people, prosecutor Underwood wrote.

“The marijuana was not in a form that the defendant could legally possess, did not comply with statutory packing requirements and exceeded an amount that could be prescribed by a doctor,” she wrote.