This is the basic dark and light sensor which using photoresistor as sensing component.
The transistor act like as a switch, when the “switch” in on condition then the relay will be activated.
The potensiometer adjust the trigger ‘on’ level. The diode in the circuit diagram shows to be 1N914. This is ok if you have a light-duty relay, also the 1N914 is a signal diode so actually does not qualify. Use a 1N4001 (or better) instead. A couple of substitutes for the 2N2222 transistor are: NTE123A, ECG123A, PN100, etc.
As light falls on the surface of the photoresistor, the?photoresistor changes it’s resistance. The more the light, the less the resistance of the photoresistor, the less the resistance, the less the voltage drop across it. The less the light, the more the resistance and thus the more the voltage drop across it.
As the voltage drop increases, so does the VB of the 2N2222 transistor and therefore the ICE increases accordingly, until the time that the current is enough to actuate the relay.
The amount of light needed to actuate the relay can be changed by changing the 100K potentiometer. Basically, any change to the potentiometer will have an effect to the voltage drop of the photoresistor, as they are both members of the voltage divider described above.
The 1N4001 diode is used to eliminate any back voltage when the relay is disarmed. It is very important to have this diode because without it, the transistor may be damaged.
The similar circuit with some improvements can be found at pcbheaven, go to this page.