Described is an algorithm to optimize traffic light activity and minimize traffic congestion. Traffic conditions are monitored by sensors and the algorithm dynamically controls the green light time to account for traffic conditions and enhance the traffic flow. In one example, the green light time of each lane is reduced or increased according to traffic flow in the lane.