This normally done using induction loops in the road surface for long term (one loop per lane), or a pressure sensitive wire across the road on top of the surface for short term installations (should be quite easily adaptable to distinguish lanes).
This works best for cars and other big chunky metal ones; may not work for bicycles or motorbikes or other small vehicles. Induction loops are prone to not detecting bicycles.