This blog post on phototransistors (light sensors) is an excerpt from Lesson B-10 of our Intro to Robotics program. Level B is the second level in Intro to Robotics and covers working with electronic components (including a variety of sensors), writing intermediate-level code commands in Python, and using a Raspberry Pi to control your electronics projects with the code you write. It contains 18 lessons including 65+ videos and 50+ projects and activities. Sample lessons and a full scope and sequence for Level B can be found here.
A light sensor will change its resistance or conductance based on the amount of light it's receiving.
One type of light sensing device is called a Photo-conductive cell. There are other types of light sensors as well, but Photo-conductive are by far the most common. They are the least expensive and most likely to be found in light-sensing projects you may find online. You may also see these devices referred to as a Light Dependent Resistor or LDR.
Photo-conductive cells will change their resistance based on the amount of incoming light. In full darkness the resistance will be highest, and full sunlight their resistance will be lowest. This resistance change can be used as part of a voltage divider to create an analog voltage based on the light level the sensor is reading.
Another type of light sensing device is called a Photo-junction device or phototransistor. A phototransistor uses the incoming light to change the conductance of a junction inside the phototransistor, allowing current to flow through the device. Due to this junction and a special clear lens designed to maximize light transmission into the junction, phototransistors offer increased light measurement sensitivity over LDRs.
Phototransistors can be used to create analog voltage levels to indicate the amount of light the device is sensing. Due to their sensitivity, these measurements can be very accurate, allowing your circuit or program to respond to various light levels with different behavior.
Even though a phototransistor looks very similar to an LED, they are very different internally. An LED is a diode that has an anode and cathode, but a phototransistor contains a tiny transistor. Transistors have a base, emitter, and collector.
The legs of a phototransistor are the emitter and collector, but there is no external connection for the base. The base is essentially made of photoconductive material and is fully contained inside the phototransistor. As more light is received, the transistor will allow more current to flow through the device.
Photoresistors do not have any polarity so they can be installed into a circuit in either direction. This is not the case for phototransistors. Since phototransistors operate using a polarized junction, it is important to have the device properly polarized in your circuit to allow for proper light measurement.
Here is an image of a phototransistor with its legs labeled to indicate direction.
The internal components at the top of the phototransistor have been outlined in gray to help you identify which direction the internal plates are pointing. The larger plate is the collector and the smaller plate is the emitter. The body of the phototransistor will contain identifiers like a flat spot in the body and different leg lengths, but don’t rely on these characteristics for identification of the emitter or collector. The flat spot and leg lengths can vary between manufacturers, so it's best to identify the emitter and collector based on the shape of the plates inside the device.
The emitter of the phototransistor must be connected to the ground side of the circuit, even if it's through one or more resistors. If not, the component will be reversed in the circuit, and current will not be able to flow through it when light is detected.
In the good examples above, the phototransistor is properly polarized with the collector toward 3.3V and the emitter toward ground. In the bad examples, the phototransistor is reversed and will not allow current to flow through the device when light is detected.
A phototransistor is included in the Intro to Robotics Level B kit and the activities in Lesson B-10 teach you to use a phototransistor in your projects.
This blog post on phototransistor (light sensor) is an excerpt from Lesson B-10 of our Intro to Robotics program. Level B is the second level in Intro to Robotics and covers working with electronic components (including a variety of sensors), writing intermediate-level code commands in Python, and using a Raspberry Pi to control your electronics projects with the code you write. It contains 18 lessons including 65+ videos and 50+ projects and activities. Sample lessons and a full scope and sequence for Level B can be found here.