My city has enough sensors in strategic places to detect all those things you mention. It's quite impressive to watch traffic flow. The censors all feed into a central computer so the lights are coordinated. This causes traffic to naturally bunch up in some places, and stay sparse in other places, in a way that minimises wait times for most people. Lights start to change as a cluster of vehicles approaches an intersection. Vehicles in a cluster move through intersections in a tight group, usually without stopping, minimising wait times for other traffic. The lights change to orange again just as the last vehicle in the cluster reaches the intersection. If no other traffic is waiting, then the lights stay green. I'm a cyclist, so I don't trigger the sensors. If there are no cars waiting at an intersection with me then the lights simply stay red for me, even without traffic, until a car arrives or I get off and press the pedestrian cross button.