A Preliminary Exploration of the Principles of Optical and Magnetic Sensors
2026-04-06 04:46:26··#1
Preface: Sensors provide a window for microprocessor systems to sense surrounding environmental conditions. Optical and magnetic sensors are widely used in determining the appearance, departure, and movement of objects. This article introduces the basic types, applications, and interface issues of optical and magnetic sensors with microprocessors. Figure 1 shows a slotted optical sensor switch, in which a light-emitting diode (LED) is placed in a plastic socket opposite a phototransistor, with a gap between the LED and the phototransistor. If an object passes through this gap, it will block the light path between the LED and the phototransistor. A slotted switch detects engine speed by placing a slotted wheel on an engine shaft. As the shaft rotates, it alternately blocks the light path. Slotted switches are also used to indicate the opening or closing of doors or covers. When a door is closed, a mark on the door falls into the slot and blocks the light path. [IMG=Slotted Optical Sensor Switch]/uploadpic/THESIS/2007/12/2007121112013957767O.jpg[/IMG] Figure 1b shows a reflective sensor, which works on a similar principle. The phototransistor on the reflective sensor intercepts light reflected from anywhere in front of the switch. Most reflective sensors have a focal length, which is the optimal distance for detecting the object being placed, typically between 0.1 and 0.5 inches. Reflective sensors typically detect engine movement by blackening the engine shaft through coloring or anodizing, and then placing a strip made of reflective material on the shaft. Because the shaft is rotating, the sensor cannot receive reflections from the black portion of the shaft, but can receive strong reflections from the reflective strip. As shown in Figure 1c, slotted or reflective light sensors have the same circuit symbol. It is important to consider the common characteristics of both types of sensors when designing the system. [IMG=Reflective Sensor]/uploadpic/THESIS/2007/12/20071211120145239846.jpg[/IMG] Current Transport Rate (CTR) The gain of the LED and phototransistor pair is typically less than 1. The current generated in the collector of the phototransistor for a given LED current is called the current transport rate (CTR). Typically, the current transfer rate (CTR) of a slot switch is 0.1, so a 10mA current in the LED will generate a 1mA current in the collector. Sometimes, CTR is described as a ratio or table showing the relationship between the collector current and the LED current. CTR depends on the characteristics of the LED and the phototransistor and varies considerably depending on the photosensor. When interfacing a photosensor with a processor, the current transfer rate has several implications. First, as shown in Figure 2, if the switch is directly interfaced to a digital input, the transistor output value will swing between valid logic levels. To ensure phototransistor saturation, the pull-up resistor value must be limited. For example, if the LED is driven by 10mA and the minimum CTR is 0.1, the pull-up resistor value is approximately 5kΩ. Lower resistance values result in better noise immunity and faster operation, but this is not suitable for all photosensors. The transistor must draw sufficient current to ensure a valid logic low level. To use a smaller pull-up resistor, a photosensor switch with a higher CTR or an LED with a larger drive current can be used. Optical sensor switches have Darlington crystal switch outputs, which typically have a higher CTR than those shown in Figure 1, but they usually only have about 20% of the output speed of a single transistor and a high saturation voltage. Reflective sensors can also be evaluated using CTR. Since the sensor depends on reflected light, the CTR depends on the surface type and the distance between the reflective surface and the sensor. The CTR of a reflective sensor depends on a standard reflective surface placed at a focal point at a specific distance from the sensor. The CTR of a reflective sensor varies depending on the device and application. If the sensor faces a surface that transitions between gray and black, the CTR will differ from the CTR measured using a white reference surface by the manufacturer. The design must accommodate the actual CTR derived from the sensor application. One method to determine the CTR range is to measure the CTR for the specific application and then compare it with the CTR measured by the sensor manufacturer using a white reference surface, thus obtaining the desired CTR reference range. Because the CTR range of optical sensors is large, it may be necessary to interface the sensor output to an analog-to-digital converter (ADC) so that software can be used to detect changes in the output level, rather than depending on the capabilities of the components generating the digital logic levels. Of course, the trade-off is the addition of an ADC and the need for more time for ADC sampling. Detection Speed The phototransistor in any optical sensor is quite slow, which limits the maximum detection speed. Typical switching times are 8 ms and 50 ms, respectively. If the driving LED within the sensor is software-controlled, this software must account for the on and off delays when reading the sensor's output. Mechanical Instability Mechanical vibrations can cause reflective sensors to malfunction. For example, by observing the luminous strip on a flat, black engine shaft, a reflective sensor can measure the number of rotations; the sensor's current output generates an interrupt signal. Sometimes, the engine will stop when the luminous strip happens to be within the sensor's detection area. Machine vibrations will cause the processor to generate numerous interrupt signals, effectively shutting down the engine. [IMG=Mechanical jitter sensor malfunction]/uploadpic/THESIS/2007/12/20071211120152397779.jpg[/IMG] A situation similar to that of a slotted sensor can be imagined: if the indicator blocking the light path only partially blurs the phototransistor, causing it to malfunction and resulting in uncertain output, the hardware design can utilize the time delay principle of comparator circuits to effectively solve this problem. Reflective sensors require some additional considerations. Reflective sensors are commonly used to sense different types of object surfaces. A typical example is a high-speed paper sorting machine. Paper quality, color, and reflective properties vary. The sensing system must be designed to handle various materials. In engine speed measurement applications, what happens when an oil film covers the flat, black element of the shaft? How does this affect the effectiveness of the sensor detecting rotation? In some cases, additional hardware or software (or both) may be needed to detect abnormal conditions. In this example, the software would have a timer to record the interruption time when the reflective sensor generates too many interrupt signals. If a sensor interrupt service routine is exited and immediately re-entered, the interrupt service routine may disable interrupts and set a flag to inform other parts of the system that a malfunction has occurred. LED Failure In systems with high safety requirements, ensuring that sensor failures do not cause safety issues is crucial. A typical example is a safety enclosure that must be closed before machine startup. This requires all dangerous moving parts to be covered, and when the enclosure is closed, the operator's hands are not in the way. When the enclosure is closed, a slotted light sensor switch and a flag blocking the light path can be used to solve the enclosure detection problem. The phototransistor emitter is connected to ground, and the collector is pulled up by a resistor. When the flag blocks the sensor, the transistor turns off, and the output goes high. An open or disconnected LED appears to the system like a closed enclosure, potentially attempting to start while the enclosure is still open. In this case, a flag is used to clear the path when the enclosure closes, making the faulty LED appear as if the enclosure is open, seemingly indicating a safe system (which is not actually the case). A safer approach is to use two sensors: one blocked when the enclosure is open, and the other blocked when the enclosure is closed. To ensure operator safety, the machine should not be started unless both sensors are in the correct state (cover closed). Sometimes, it is necessary to know if the LED in the light sensor is faulty. In this case, a slotted switch can be used to determine if the engine is running. If the engine stops running, it can detect if the engine is blocked or if the sensor's LED is faulty (or disconnected), thus facilitating the display of correct fault diagnosis information. Figure 3 is a simple example of detecting a faulty LED. The comparator senses the voltage on the positive terminal of the LED. When the LED is on, it will cause the voltage to drop by about 1.2V (typical), so the comparator output goes high. If the LED is turned on, the voltage at the positive terminal will rise to Vcc (Vcc must be greater than 3V for the LED to work). The LED circuit shown in the figure is always on. This method can also be used for switching LEDs, but the voltage drop of the switching transistor must be taken into account when selecting the reference voltage. When the LED is off, the software will not detect the comparator output. Although an open LED is very similar to a short-circuited LED, another comparator can be added to detect short-circuit conditions. The reference voltage is 0.6V. If the voltage drops below the reference voltage, the system software will indicate an error. Other Optical Sensor Solutions Besides slot switches and reflective sensors, optical sensors can also be used as optical isolators, as well as discrete optical sensor transmitters and receivers. Optical isolators (also called optocouplers) can house LEDs and phototransistors within a package similar to an IC. Optical isolators cannot be used to detect mechanical motion; instead, they provide electrical isolation between two circuits. Optical sensors are sealed, so they cannot block the light path. Optical isolators are commonly used to isolate high-voltage circuits from the microprocessor that controls them. Musical Instrument Digital Interface (MIDI) technology uses optical isolators to connect electronic musical instruments, preventing problems caused by different ground voltages. Figure 4 shows the process of a signal being transferred from one circuit to another in an optical isolator, even though the ground and the system's power interface may be completely separate. Even in a single system where a ground wire appears identical, optical isolators can be used to isolate ground loops or block ground noise (such as pulse-width modulation engine noise) from logic/analog grounds. Optical isolators output logic levels, unlike phototransistors. These optical isolator devices have internal ICs that convert the analog output to a digital voltage output. [IMG=Optical Isolator Signal Transmission]/uploadpic/THESIS/2007/12/2007121112020799636T.jpg[/IMG] Optical isolators have the same gain and speed issues as optical sensors; however, because the LED is closer to the phototransistor socket, the CTR of optical isolators is typically higher, usually in the range of 0.2-1. Optical isolators are generally faster than optical sensor switches. A common 4N35 optical isolator has a 10ms on/off time, allowing it to transmit signals up to 10kHz. For high-speed isolation, fast optical isolators are typically used. The 6N136, with a speed of approximately 1MHz, achieves high speed by interfaced a photodiode to a transistor. Discrete Optical Sensors Some designs require discrete optical sensor elements—LEDs or phototransistors. This is similar to the components encapsulated in optical sensor switches, typically infrared sensors. They are often used to detect obstructions between an LED and a phototransistor, as the physical characteristics of these locations do not allow for slotted switch sensors. Discrete components interface in the same way as optical sensor switches or phototransistors, but with a few additional considerations. Because the distance between the sensor and phototransistor is typically large, the CTR is low. Software adjustment of the LED current or sensing threshold is used in the circuit to ensure stable and repeatable operation. In some cases, lenses are needed for focusing the light; software adjustments can compensate for inconsistencies caused by the large distance between the LED and phototransistor and accumulated tolerances. Within an optical sensor switch, the LED and phototransistor must be matched to the same infrared wavelength (IR). Although most IR phototransistors and LEDs are well-matched, in practice, these components operate near the peak wavelength of the IR range. When using discrete components, it is best to use LEDs and phototransistors designed for the same IR range. If the distance between these components is different, the LED at one end of its coupling distance and the phototransistor at the other end constitute a system with a lower CTR. Magnetic Sensors The simplest magnetic sensor used in embedded devices is the Hall effect sensor. The Hall effect was discovered by Dr. Edwin Hall in 1879. In the presence of a magnetic field, a current-carrying semiconductor device placed in the magnetic field will generate a voltage, and this voltage and current are proportional to the magnetic flux density. Hall effect sensors are fabricated on a silicon wafer and generate voltages of only a few microvolts/gauss. Therefore, a high-gain amplifier is needed to amplify the signal output from the Hall element to a usable range. Hall effect sensors integrate the amplifier and sensor unit in the same package. Hall effect sensors are used when the sensor output is required to be proportional to the magnetic field, or when a switch needs to change state when the magnetic field exceeds a certain level. Analog Hall effect sensors are suitable for applications where it is necessary to know the exact distance between the magnet and the sensor, such as sensing whether an oscillating arm is actually moving. Hall effect sensors are best suited for applications that detect whether a magnet is approaching the sensor, such as sensing whether a safety shield is open or closed. The output of an analog Hall effect sensor can be interfaced to a comparator or an ADC similar to any other voltage output sensor. It is important to note that analog output sensors provide an output quantity proportional to the supply voltage. To obtain accurate, noise-free output, a noise-free, well-tuned power supply must be used to power the sensor. In the absence of a magnetic field, the output of a typical analog Hall effect sensor is the midpoint between the supply voltage and ground. When the north magnetic pole is near the sensor, the voltage moves towards ground, while when the south magnetic pole is near the sensor, the voltage moves towards the positive supply. Hall effect switches generate digital outputs to indicate the presence of a magnetic field. When magnetic force (the point of movement) is sensed, the Hall effect sensor drives the output; when the magnetic field drops to a certain level (release value), the Hall effect sensor disables the output. A certain hysteresis range exists between the release point and the operating point. Hall effect switches can be divided into two categories—unipolar and multipolar switches, sometimes also called latch-free and latch-up switches. Bipolar switches have a positive (south magnetic pole) operating point and a negative (north magnetic pole) release point. Unipolar switches have a positive (south magnetic pole) operating point and a sub-positive release point. In both cases, the actual operating and release points vary with temperature. Single-pole and double-pole switches typically have an open-collector output that is not connected to an external resistor. Hall effect sensors are typically packaged in a 3-wire package similar to a TO-92 transistor, with the three wires being power, ground, and output. Although some sensors operate at 30V or higher, the supply voltage for these sensors is usually 5-10V. When using Hall effect sensors, it is important to address magnetic field deviation. If using a magnet, such as a rotating shaft, ensure that the magnet does not over-magnetize the shaft, otherwise it will affect the sensor's output. Remember that magnetic fields decay with the square of the distance. Due to the influence of magnetic field strength, the output of an analog Hall effect sensor may be linearly related to the strength of the magnetic field, but not to the distance. Sawtooth Hall effect sensors consist of a magnet and a Hall effect sensor within the package, as shown in Figure 5. By placing the sensor near the sawtooth, they have been designed to measure the rotation of toothed devices. As each tooth passes the sensor, it acts on the magnetic field between the magnet and the Hall effect sensor, generating an output pulse.