How do the streetlights turn on automatically at night?

The most commonly used component in streetlights is called a cadmium sulphide photoresistor, or a CdS cell for short. The CdS cell changes the resistance of a circuit depending on the amount of light shining on it. When lots of light falls on a CdS cell, then the resistance is very low, which means it conducts electricity well. When there is not much light, the photo-resistor has a high resistance which means not much current can flow.
This change in current can then be used to control a relay. A relay is basically an electromagnetic switch; when the electromagnet has a high current (lots of light falling on the photo-resistor – daytime) then it pushes the switch open so no current can fl ow to the streetlight. When it gets dark, then not much current can flow to the electromagnet so the switch closes and allows electricity to flow to the streetlight, turning it on.