This is a very nice explanation of how mechanical traffic light systems work. It also shows how mechanical traffic light controllers can be connected into computerized systems and turned into remote-control units for a city-wide signaling (in this case, the city is Toronto):
According to this page, a typical intersection costs about $150,000, including the controller, the lights and the poles/wires to hang the lights.
Most modern systems use wire loops embedded in the road to detect when cars are waiting. To learn more about these loops and how they work see: