Phototransistors are used in a variety of applications. A light-operated relay circuit is shown in below Figure (a). The phototransistor Q1 drives the BJT Q2. When there is sufficient incident light on Q1, transistor Q2 is driven into saturation, and collector current through the relay coil energizes the relay. The diode across the relay coil prevents, by its limiting action, a large voltage transient from occurring at the collector of Q2 when the transistor turns off.
The below Figure (b) shows a circuit in which a relay is deactivated by incident light on the phototransistor. When there is insufficient light, transistor Q2 is biased on, keeping the relay energized. When there is sufficient light, phototransistor Q1 turns on; this pulls the base of Q2 low, thus turning Q2 off and de-energizing the relay.