What is a Passive Light Sensor?
A Light Sensor is something that a robot can use to detect the current ambient light level - i.e. how bright/dark it is. There are a range of different types of light sensors, including 'Photoresistors', 'Photodiodes', and 'Phototransistors'. The sensor we will be using here is called a Phototransistor.
To understand what a phototransistor is, we must first understand what a transistor is:
A regular transistor is an electrical component that limits the flow of current by a certain amount based on the current applied to itself through another pin to accomplish this, there is a collector, emitter, and a 'base', which controls how much current can pass through the collector through to the emitter.
A phototransistor, on the other hand, uses the level of light it detects to determine how much current can pass through the circuit. So, if the sensor is in a dark room, it only lets a small amount of current through. If it detects a bright light, it lets a larger amount of current through.
So what happens when the phototransistor changes the current that can pass through it? If we connect it like we normally would, to the digital ports, the value would either be 0 (for dark) or 1 (for light)
However, this is rather imprecise (where is the cutoff between light and dark?), which ordinarily would be a problem. Luckily, we have a second option which is far better suited to this type of sensor: an analog port.
What is Analog?
Up to this point, you have only used the board's Digital ports, which can accept either a 0 (a value of 0 volts) or a 1 (a value of 5 volts) as input, and give the same as output (PWM just cycles this on and off very quickly). Analog ports, on the other hand, can accept an infinite range of values between 0 volts and 5 volts. This means that our robot can translate these into meaningful sensory input that can convey far much more data. In the case of the phototransistor, this means that we can tell not only if it is 'dark' or 'light', but all the values in between. This is vitally important for an application like this, and indeed, for many sensors, since being able to return a wide range of values is integral to their function.
There may be a time you find yourself using a photoresistor. A photoresistor operates similarly to a phototransistor, except it changes its resistance based on the amount of light, instead of current. Which means that they read the opposite of phototransistors: low current (high resistance) means that there is much light, and high current (low resistance) means that it is dark.
As a side note, photoresistors also tend to be less sensitive than phototransistors.
The Lego Light Sensor
The Lego light sensor is a dual functioning photoresistor light sensor which does well in both passive and active roles. In this case, we will be focusing on the "passive" function of the light sensor, that is to say its ability to read the ambient lighting in its current location. The "active" function, which involves reading the darkness/brightness of a surface, will be covered in the next section.