A transistor may be connected in a way that will switch on and off a load (RL) according to a sensor. In our example, the sensor is an LDR. The LDR is a resistor that will change it's resistance according to the light falling on the sensor. The left circuit will switch on the load when the LDR is in dark, and the right will switch on the load when light fall on the LDR.
The potentiometer RS will control the sensitivity of the automation. You should consider using a potentiometer 10Kohms. Also note the resistor on the left circuit labeled RP. This resistor is used to protect the transistor when the potentiometer is switched to low values. This RP should be from 1Kohm to 22Kohms. Select according to your LDR.
You should consider using low current loads using this circuit. There is a point that the transistor will not be either on or off. In this case, there is danger overheating the transistor if you have big loads like lamps and motors. In this case, you should use a second transistor connected as a driver.