Phototransistor: what it is and practical examples with L14G2 and KY-032

  • The phototransistor converts light into electrical signals efficiently and amplified.
  • Models such as L14G2 and KY-032 are widely used in obstacle detection and integration with microcontrollers.
  • The KY-032 stands out for its ease of use and customizable fit in educational robotics projects.

Example of phototransistor and KY-032 and L14G2 sensors

Modern electronics has made tremendous progress thanks to components capable of interacting with the environment, and within this fascinating world, phototransistors occupy a prominent place for their ability to translate light into highly useful electrical signals. If you've ever been interested in obstacle sensors in robotics or light detectors in intelligent systems, it's very likely that behind these applications lies a phototransistor like the L14G2, or modules like the KY-032, that combine infrared emitters and receivers to make magic.

In this article, we'll dive deep into the world of phototransistors, explaining what they are, how they work, how they differ from other optical sensors, and how popular models like the L14G2 and KY-032 are similar and different. We'll also cover practical usage examples, connection diagrams, codes, and even assembly tips so you can apply them to your own projects, whether you're a curious beginner or already experienced in the maker world.

What is a phototransistor and how does it work?

The phototransistor is a semiconductor device that bases its operation on the detection of light to generate an electric current proportional to the light intensity it receives. While a conventional transistor would switch based on the current applied to the base, the phototransistor uses light instead of an electrical signalThis makes it the ideal choice for applications where presence or light intensity detection is key.

It was born from developments at Bell Labs in the 50s when they realized that transistors, by removing their opaque cover and exposing the semiconductor material to light, generated an internal current without needing to electrically excite the base. Thus was born the first phototransistor, marking a major advance in optoelectronics and enabling the development of all types of sensors.

At the structural level, the phototransistor maintains the typical architecture of the bipolar transistor, but with a larger base and collector region to maximize light collection. The most commonly used material is silicon, although there are also devices based on gallium arsenide or germanium for specific applications, such as infrared or ultraviolet light detection.

Symbols and types of phototransistors

NPN and PNP phototransistor symbol

In electrical diagrams, the phototransistor is represented as an NPN or PNP type transistor, but with the addition of two arrows pointing towards the base-collector junction, indicating light sensitivity. If the emitter arrow points outwards, it is NPN; if it points inwards, it is PNP.

The base is usually left disconnected (not connected to the circuit), as light is sufficient to activate internal conduction. However, in advanced setups, the base can be polarized to modify the activation threshold as required.

ltr390
Related article:
Discover the LTR390 UV Light Sensor: Features and Uses

Technical properties of phototransistors

The choice of a phototransistor depends on several technical characteristics that should be known in order to make the right choice of one component or another depending on the application:

  • Gain (β): Multiplies the current generated by light. It can vary from 50 to 10.000 times in advanced devices.
  • Sensitivity: Phototransistors are very sensitive even at low light intensities.
  • Response time: From several microseconds to nanoseconds depending on the material and structure.
  • Operating frequency: Limited in some cases to about 250 kHz, although there are high-speed phototransistors that far exceed XNUMX MHz.
  • Dark current: A small current that flows without incident light; this can be useful or problematic depending on the installation.
  • Material: Silicon, gallium arsenide, germanium, gallium nitride or indium phosphide depending on the light spectrum to be detected.
  • Spectral range: Silicon materials tend to respond well to visible and near-infrared, while other materials cover UV to deep IR.

Main applications of phototransistors

They are extremely versatile, which explains their presence in a multitude of commercial and industrial solutions. The most common applications are:

  • Ambient light sensors to activate automatic lighting systems or regulate the intensity of screens.
  • Obstacle detectors in robotics, as we will see with the KY-032, very useful in line-following robots or sumos.
  • Optical counters (for example in access control systems, or in mass production counting machines).
  • Card readers and optical encoders, where light reflects on black/white bands or on the card chip itself.
  • Security systems, such as infrared barriers on automatic doors or anti-intrusion alarms.
  • Remote controls and infrared receivers, where the IR signal modulates the data transmission.
  • Motion detectors and counting systems in home automation or industrial applications.

The L14G2 phototransistor: characteristics and uses

The L14G2 is one of the best-known phototransistors and is used in a multitude of applications thanks to its reliability, low cost, and ease of integration. It is of the NPN type and is optimized to work in the visible and near-infrared light range, making it ideal for educational and experimental projects.

Its specifications include high gain, low dark current, and fast response times, making it highly valued in speed sensors, optical coding systems, and especially in infrared barrier presence detection assemblies.

The typical L14G2 package is a metallic TO-18, with a transparent window to allow maximum light capture. Connecting it is extremely simple:

  • Manifold: connected to the supply voltage by a resistor.
  • Transmitter: to ground (GND).

When light is applied to the package, the current between collector and emitter increases and can be detected as a logic level change in the control circuit (e.g., a microcontroller or Arduino).

as7341
Related article:
Everything you need to know about the AS7341 visible light sensor

The KY-032 sensor: operation and advantages

The KY-032 is a sensor module based on infrared emitters and receivers, designed for short-range obstacle detection, between 2 and 40 cm, and compatible with Arduino and other microcontrollers. It integrates two key elements: an IR emitting LED and a receiving phototransistor, configured so that the receiver only detects light reflected by an obstacle.

This sensor has become very popular in entry-level robotics, especially in line-following robots, minisums, and obstacle avoidance systems. It also offers the possibility of adjusting the detection threshold using two potentiometers, one for sensitivity (minimum signal level to activate the output) and another for the emission frequency.

Technical characteristics of the KY-032:

  • Supply voltage: 3.3V – 5V (ideal for Arduino).
  • Consumption: ≥ 20 mA.
  • Operation range: -10 °C to +50 °C.
  • Detection distance: 2-40 cm (variable depending on the setting of the potentiometers and the reflectance of the object).
  • Detection angle: Approximately 35°.
  • Output signal (OUT): low level if there is an obstacle, high if it is not detected.
  • Pins: GND, VCC, OUT (signal), EN (enable).

The KY-032's most notable advantage is its ease of use and versatility, as it easily adapts to all types of microcontroller projects without the need for additional components or complex calibrations.

Differences and similarities between L14G2 and KY-032

Both devices are closely related in terms of their operating principle, but their use and level of integration differ significantly:

  • L14G2 is a “pure” phototransistor, suitable for integration into any custom electronic assembly, whether as a light barrier, presence sensor, etc. It offers great flexibility for assembling custom circuits.
  • The KY-032 is a module that integrates an infrared transmitter and receiver on a single board, with adaptation and output electronics ready to connect to a microcontroller without complications. It is the ideal option for those looking for speed, compatibility and ease of use.
  • The L14G2 can be used in complex schemes where customization of all electrical parameters is required, while the KY-032 focuses on plug-and-play obstacle detection, especially in educational robotics.

Connection example and code with Arduino: KY-032

One of the key applications is the integration of the KY-032 into autonomous robots that require obstacle avoidance. Its connection is straightforward and suitable for all levels, from children to experienced makers.

Necessary material:

  • Arduino (any model: UNO, Nano, Pro Mini, Leonardo…)
  • KY-032 Sensor
  • Connection cables (can be male-female or directly on the breadboard)
  • (Optional) LED or warning buzzer

Pin connection:

  • GND of KY-032 to GND on Arduino
  • VCC of KY-032 to 3.3V or 5V on Arduino
  • OUT to a digital pin, for example D3
  • EN not connected (optional, you can leave it on air if you don't need enable/remote)

Basic code (obstacle detection and serial monitor warning):

int sensorPin = 3; // Pin where OUT is connected void setup(){ Serial.begin(9600); pinMode(sensorPin, INPUT); } void loop(){ bool detected = digitalRead(sensorPin); if(detected == HIGH){ Serial.println("No obstacles"); }else{ Serial.println("Obstacle detected"); } Serial.println("------------------------"); delay(500); }

This code can be easily extended to activate an LED, buzzer, or to control the movement of motors, allowing the robot to stop or turn if it detects a wall or any object in front of it.

Setting and adjusting the KY-032

The KY-032 includes two potentiometers that allow you to customize the module's operation. One adjusts the detection signal threshold level (more or less sensitive), and the other modifies the transmitter's transmission frequency. This way you can adapt it according to the reflectance of the materials, the ambient lighting and the desired distance.

Other components on its PCB include SMD resistors, indicator LEDs, and the 4-pin connector. The adjustable optical filter and internal bandpass (around 38 kHz) filter out interference and ensure it only responds to infrared light of that frequency.

Materials and assembly recommendations

To work comfortably with the KY-032 and L14G2, you can use a breadboard for quick testing or even solder the wires directly if you're looking for permanent integration. Always remember to check the pin polarity before applying power to the module to avoid damage.

The KY-032 fully supports both 3.3V and 5V, making it suitable for most Arduino boards and microcontrollers. If you use the L14G2, you'll need to add the appropriate resistor to the collector to adjust the sensitivity and prevent overheating.

If you want to use multiple units on the same robot (e.g., for forward and side detection), simply connect each OUT to different digital pins and adapt the code to control the movement or response depending on the area where the obstacle is detected.

Some curiosities and additional advantages

Compared to other sensors, phototransistor-based sensors offer an excellent balance between cost, speed, and ease of integration. Unlike ultrasonic sensors (such as the famous HC-SR04, which measures distances by echo), IR sensors require no moving components, are completely silent, and can operate in environments where sound is not practical.

Another advantage is its immunity to visible light (thanks to the internal optical filter), which minimizes false detections due to changes in ambient lighting. Additionally, both the L14G2 and KY-032 can be used in industrial or outdoor environments with minimal adaptations.

Finally, it should be noted that the cost of both devices is very low, with the KY-032 costing around €1,5-€4 and the L14G2 even cheaper, allowing anyone to experiment, learn, and create their own projects from scratch.

vl53l4cd
Related article:
How to measure distances with the VL53L4CD sensor and Arduino

Although these sensors are low-cost and easy to use, they are highly useful in real-world applications, enabling everything from educational projects to complex industrial systems. Phototransistors and modules like the KY-032 provide great versatility for integrating light or obstacle detection into any technological creation.