This is one of the common circuit blocks being used both in digital and analog electronics. Its output is dependent on the relationship of its two input pins. One of the inputs is set to give the reference voltage while the other one is commonly connected to different sensors. If the reference voltage was overcome by the input connected to the sensor, the output of the comparator changes.
In this circuit, the we'll use an LDR.
The advantage of a comparator IC than an opamp used as an comparator is the property of IC comparators to be open collector output. Having this feature, we can set the output of the comparator beyond its biased voltage.