How do stop lights work?

I realize how stupid a question this is but other than peak times, how does it know when to change.  I assume that at peak times there are programmed timers that change. Thanks.
There are sensors that count the number of cars coming along a road and work out which one needs to be green the most [1]. 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 [2]. 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 [2]. This system is called Vehicle Actuation and is the more commonly used method [3]. There are some junctions that use Fixed Time operation that keeps one set green for a pre-determined length of time, no matter how much traffic there is [3]. In order to minimize stops, signals are coordinated to provide progression for vehicles, which means the light turns green prior to their approach [4].
Traffic lights most commonly work on simple timers that cycle through green, yellow, and red at regular intervals to ensure a consistent flow of traffic in all directions through an intersection [1]. However, in areas where traffic can be sporadic and unpredictable, timer-based systems don't work as well and sensor-based traffic signals that only function when traffic is present are used instead [1, 2]. Some systems use lasers, rubber hoses filled with air, or video cameras to detect the presence of cars [2]. Another popular type of sensor is an inductive loop system that relies upon a coil of wire embedded in the road's surface [2, 5]. The wire detects changes in magnetic fields when vehicles (large metal objects!) arrive at the intersection, controlling the duration of the light [3, 5]. Sometimes, traffic lights are centrally monitored and controlled by computers to coordinate traffic lights in real-time and deal with changing traffic patterns [4].