There are sensors installed on the approach to a traffic light, either under the road’s surface or on top of the light itself. These count the number of cars that are coming along the road and work out which one needs to be green the most.
If a stream of cars is coming from one direction and none from the other, the signals will decide to keep the busy area green. However, if a sufficient number of cars start to build up in the other direction, the light will turn red and the other one green.
This system is called Vehicle Actuation and is the more commonly used method. There are some junctions, however, that use Fixed Time operation that keeps one set green for a pre-determined length of time, no matter how much traffic there is.
The lights themselves are operated on a fixed circuit, with high-powered LEDs behind each glass circle. Once the signal has been switched off to the green light, power passes to the amber, then red.