Every optoelectronic part rests on one fact: an electron crossing an energy gap either spits out a photon or is knocked loose by one. Run that physics forward and you get an LED; run it backward and you get a solar cell. This chapter turns that single idea into glowing displays, light sensors, and circuits that talk without touching.
You buy two identical red LEDs. You take the first, push its longer leg (the anode) onto the + terminal of a fresh 9 V battery and its shorter leg (the cathode) onto the − terminal. It flashes — bright, just for an instant — and then it is dark forever. A faint smell of hot plastic.
Your friend takes the second LED, solders a small resistor in series with it, and connects that across the same 9 V battery. Hers glows a steady, cheerful red. It is still glowing a year later. Same part, same battery. One died in a heartbeat; one lives indefinitely. The only difference is a part that cost less than a penny.
This is not a trick. It is the central fact of optoelectronics, and it follows from how an LED behaves electrically. An LED is a diode: once it conducts, it clamps the voltage across itself to a nearly fixed forward voltage Vf (about 1.8 V for red) and then it barely resists current at all. Its I–V curve is almost vertical past Vf. So when you put 9 V across a part that only ever drops 1.8 V and has near-zero internal resistance, Ohm's law screams: the current shoots toward whatever the battery can deliver — hundreds of milliamps — far past the ≈20 mA the chip can survive. The junction overheats and fails in milliseconds.
The resistor fixes everything by eating the leftover voltage. Of the 9 V, the LED keeps its 1.8 V; the resistor must drop the remaining 7.2 V. Choose the resistor so that dropping 7.2 V corresponds to a safe 20 mA, and the LED is protected. The whole rest of this chapter is the physics that makes Vf what it is, and the engineering of that one resistor — plus everything that happens when you run the same junction in reverse and let light make the current instead.
Left: bare LED across 9 V — runaway current, dead part. Right: LED with a 360 Ω resistor — pinned to 20 mA. Click Connect Power to energize both. Watch the current readouts.
You will compute the right resistor for any LED on any supply, predict the forward voltage of an LED from its color, drive seven-segment displays and series strings, read light with a photoresistor, harvest power with a solar cell, and isolate one circuit from another with an optocoupler — all from the one electron-photon idea.
Before we can explain why a red LED and a blue LED behave differently, we need to know what light is from a circuit's point of view. Light is a stream of photons — discrete packets of electromagnetic energy. Each photon carries a fixed amount of energy set entirely by its frequency, and frequency is just another name for color.
The defining relation is Planck's: the energy of one photon equals Planck's constant times its frequency. And since all electromagnetic waves travel at the speed of light c, frequency and wavelength are locked together by c = fλ. Combining the two gives the form we use constantly:
where h = 6.63×10−34 J·s and c = 3.0×108 m/s. The key takeaway: shorter wavelength means higher energy. Blue light (short λ) is more energetic than red light (long λ). That single inequality is what forces a blue LED to need a higher forward voltage than a red one — a fact we'll cash out in Chapter 3.
Visible light occupies a narrow slice of the electromagnetic spectrum, roughly 400 nm (violet) to 700 nm (deep red). Below 400 nm is ultraviolet; above 700 nm is infrared (the "color" your TV remote and a CD laser emit, invisible to your eye but plain to a photodiode). The everyday LED colors live at: red ≈650–660 nm, orange/yellow ≈590–610 nm, green ≈565 nm, blue ≈470 nm.
Take a green LED emitting at λ = 565 nm = 565×10−9 m. Its photon energy is:
Dividing by the charge on one electron (1.6×10−19 C) converts joules to electron-volts: 3.52×10−19 / 1.6×10−19 ≈ 2.2 eV. The frequency is f = c/λ = 3.0×108 / 565×10−9 ≈ 5.31×1014 Hz — 531 trillion oscillations per second.
Now compare blue at λ = 470 nm: E = (1.989×10−25)/(470×10−9) ≈ 4.23×10−19 J ≈ 2.6 eV. Blue photons carry about 20% more energy than green, and that gap shows up directly at the LED's terminals as a higher forward voltage.
Drag the wavelength slider across the visible band. The panel paints the actual color and computes the photon energy E = hc/λ (in joules and eV) and frequency f = c/λ live.
An LED is a light-emitting diode — a PN junction, just like the diodes in Chapter 4, but built from semiconductor compounds whose physics make it dump its energy as light rather than as heat. To see how, recall what a forward-biased junction does to its charge carriers.
On the N side of the junction there are mobile electrons; on the P side there are holes (empty bonds that behave like positive charges). When you forward-bias the diode — positive on the P side (anode), negative on the N side (cathode) — you push electrons toward the junction and holes toward it too. At the junction they meet and an electron drops into a hole. This is recombination.
Here is the crucial part. An electron in the N-side conduction band sits at a higher energy than a hole in the P-side valence band. When it recombines, it must shed that energy difference. The size of that difference is the material's band gap Eg. In ordinary silicon diodes the energy leaks out as heat (lattice vibrations). In LED materials — gallium arsenide, gallium nitride, and their alloys — the electron instead emits a single photon whose energy equals the band gap:
So the band gap chosen by the chemist sets the photon energy, which sets the wavelength, which sets the color. A wide-gap material (gallium nitride, ~2.6 eV) emits blue; a narrower gap (gallium arsenide phosphide) emits red. And because the electron has to fall through that band gap, the forward voltage you must apply is approximately Eg expressed in volts — wider gap, higher Vf. This is the through-line: band gap → color → forward voltage, all the same number wearing different clothes.
For a green LED we found a 2.2 eV photon. That implies a band gap of about 2.2 eV, which implies a forward voltage of roughly 2.0–2.1 V (a little less than the ideal because of how the junction conducts). For blue at 2.6 eV, Vf climbs to ~3.2–3.4 V. For red at ~1.9 eV, Vf ≈ 1.8 V. You can practically read an LED's color off its datasheet's Vf and vice versa — they are the same physics.
An electron (teal) crosses the junction, drops into a hole (warm), and emits a photon of energy equal to the band gap. Slide the band gap to change the color of the emitted light — wider gap, bluer photon, higher Vf.
Now we solve the dead-LED problem for real. We have a supply voltage Vin, an LED that drops a fixed Vf, and a target current ILED (usually about 20 mA). We need the series resistor Rs that makes it all work. Kirchhoff's voltage law says the voltages around the loop must add to the supply:
The resistor carries the same current as the LED (they're in series) and must absorb everything the LED does not. Solving for Rs gives the single most-used formula in hobby electronics:
Read it as: leftover voltage divided by desired current. The "leftover voltage" Vin − Vf is exactly the 7.2 V the resistor had to eat in Chapter 0. Bigger supply → more leftover → bigger resistor. Higher Vf (bluer LED) → less leftover → smaller resistor.
Red LED, Vf = 1.8 V, target I = 20 mA = 0.020 A, supply 9 V:
360 Ω is not a standard E12 value, so round up to the nearest standard part: 390 Ω. Rounding up gives slightly less current, which is the safe direction (slightly dimmer, never overdriven). With 390 Ω the actual current is (9−1.8)/390 = 18.5 mA — perfect.
The resistor is dissipating real power and you must not exceed its wattage. With the 360 Ω value:
That's 144 mW, comfortably under the 250 mW of a standard ¼ W resistor. (Equivalently P = VR·I = 7.2×0.020 = 0.144 W — same answer.) On a lower 5 V supply the leftover is smaller, so both R and its power drop; on a 24 V supply with one LED, the resistor eats ~22 V and dissipates far more — always check.
Pick an LED color (loads its Vf), set the supply and target current. The widget computes Rs, the nearest standard resistor, the resulting current, and resistor power — and drives a live brightness gauge. Hit Remove Resistor to short it out and watch the LED blow.
One LED with one resistor is the easy case. Real projects use many LEDs — strings, matrices, RGB units, numeric displays. The mistakes people make almost all come from forgetting that LEDs are current devices with a clamped voltage.
Put several LEDs in series and the same current flows through all of them — so they're equally bright, which is exactly what you want. Their forward voltages add up. The resistor formula generalizes by summing Vf:
Worked example C: four white LEDs (Vf = 3.4 V each) in series need 4×3.4 = 13.6 V of drop. From a 24 V supply at 20 mA: Rs = (24 − 13.6)/0.020 = 10.4/0.020 = 520 Ω. There is a hard limit: the sum n·Vf must stay below your supply (with margin). A good rule is to keep the total LED drop under ~80% of Vin, leaving the resistor enough headroom to actually regulate current as the supply sags.
It is tempting to wire several LEDs in parallel behind a single resistor. Don't. Real LEDs have slightly different Vf values, and the one with the lowest Vf hogs almost all the current — it runs bright and hot while the others stay dim, then it burns out and dumps its current into the next one. The fix: one resistor per LED branch, so each branch sets its own current independently.
A seven-segment display is just seven (plus a decimal point) LEDs arranged as a figure-8, labeled a–g. Light the right subset and you form any digit 0–9. In a common-cathode display all cathodes join to ground and you drive each segment's anode high (through its own resistor); in common-anode it's the mirror image. Each lit segment still needs current limiting — one resistor per segment, sized with the same Rs = (Vin−Vf)/I formula.
Click individual segments (a–g) to toggle them, or press a number button to light the correct pattern. This is common-cathode wiring — each segment is one LED to ground.
So far we've run the electron-photon trade in one direction: current in, light out. Now run it backward. If a photon can carry away energy when an electron recombines, then a photon can also deliver energy to liberate an electron. That is the basis of every light sensor in this chapter, starting with the simplest: the photoresistor.
A photoresistor (also LDR, light-dependent resistor, usually made of cadmium sulfide, CdS) is a resistor whose value depends on how much light hits it. In the dark, few electrons are free, so resistance is high — often megohms. Under bright light, photons knock loose many carriers, resistance plunges to hundreds of ohms. The relationship is inverse: more light → less resistance.
By itself a changing resistance does nothing useful — you can't read it directly. The trick is to put the LDR in a voltage divider with a fixed resistor, turning resistance changes into voltage changes that a microcontroller or comparator can read. From Chapter 2, the divider output is:
Which leg the LDR occupies decides the polarity of the response. Put the LDR on top (R1) and a fixed resistor on the bottom (R2): in bright light the LDR is small, so most of Vin appears across R2 and Vout is high — a light-activated output. Swap them and you get a dark-activated output, the classic automatic-nightlight circuit.
Use Vin = 5 V, a fixed R2 = 10 kΩ on the bottom, and the LDR as R1 on top. In darkness the LDR is ~1 MΩ:
In bright light the LDR drops to ~1 kΩ:
So one cheap part swings the output from 0.05 V to 4.55 V as the room goes from dark to bright — a clean, readable signal. Feed it into a comparator with a threshold around 2.5 V and you have a switch that flips when the light crosses a level you choose.
Drag the flashlight brightness to drop the LDR's resistance from megohms (dark) to hundreds of ohms (light). The voltmeter reads Vout live. Toggle which leg the LDR occupies to flip between light-activated and dark-activated.
The photoresistor is slow and crude. The precise light detectors are PN-junction devices run in reverse — the very same junctions that make LEDs, now used as receivers. When a photon with energy above the band gap strikes the depletion region, it knocks an electron free, creating an electron-hole pair. The junction's built-in field sweeps them apart into a current. Light in, current out: an LED run backward.
A photodiode is a PN junction optimized to catch light. You can operate it in two modes:
A solar cell is simply a large-area photodiode in photovoltaic mode. Each silicon cell produces an open-circuit voltage of about 0.45–0.5 V in full sun, almost independent of size; the area sets the current. To get useful voltages you wire cells in series (their voltages add, just like series LED Vf): a "12 V" panel is ~36 cells in series. For more current, wire strings in parallel.
Worked example: you want ~6 V to charge a battery. At 0.5 V per cell, you need 6/0.5 = 12 cells in series. If one cell delivers 0.1 A in your light and you need 0.3 A, put three such 12-cell strings in parallel: 0.5×12 = 6 V at 3×0.1 = 0.3 A.
A phototransistor is a transistor whose base current comes from light instead of a wire. The photo-generated current at the base-collector junction is amplified by the transistor's gain (β, typically 100–500), so a phototransistor produces far more current per photon than a bare photodiode — much more sensitive, though slower. It's the detector of choice when you need a strong signal and don't need blazing speed, which is exactly the situation inside an optoisolator (next tab).
Sweep across a solar cell's operating points. The current stays near its light-set value until voltage approaches ~0.5 V, then collapses. Power = V×I peaks at the "knee" — the maximum power point. Slide the illumination to scale the whole curve.
Here is a problem the LED and the phototransistor solve together beautifully. Suppose a delicate 3.3 V microcontroller needs to switch a noisy 240 V mains load. Wire them directly and a voltage spike on the mains side could destroy your micro — or you. You need them to communicate without sharing any electrical connection. The answer is to send the signal as light across a gap.
An optoisolator (optocoupler) packs an LED facing a phototransistor inside one opaque case. The micro drives the LED; the LED's light hits the phototransistor; the phototransistor switches the high-voltage circuit. The two sides never touch — the only bridge is a beam of light across a few millimeters of clear epoxy. Isolation voltages of several thousand volts are routine. A surge on the output side stops dead at the gap.
The key spec is how much output (collector) current you get per unit of input (LED) current. That's the Current Transfer Ratio:
A typical optoisolator has CTR around 50–100%. Worked example: drive the LED at ILED = 10 mA through a part with CTR = 60%. The phototransistor can sink up to IC = 0.60×10 = 6 mA. If your output load needs more than that, you either raise the LED current or pick a higher-CTR part (or one with a Darlington output stage, where CTR can exceed several hundred percent).
Don't forget: the LED inside still needs a current-limiting resistor on the input side, sized with the same Rs = (Vin−Vf)/I formula from Chapter 3 (its Vf is usually ~1.2–1.4 V, often infrared). Everything you learned about driving LEDs applies to the input of an optoisolator.
Left side (input): an LED driven at ILED. Right side (output): a phototransistor, fully isolated. Adjust the LED current and the CTR; the output collector current and the light beam scale accordingly. Note the two sides share no wire.
Optoelectronics is one idea seen from both ends. An electron crossing a band gap either emits a photon (LED, laser diode) or is freed by one (photoresistor, photodiode, solar cell, phototransistor). The photon's color is its energy, E = hc/λ, and that energy equals the band gap, which equals (roughly) the forward voltage. Drive LEDs by current, sense light by turning current or resistance into voltage, and bridge two circuits with light alone.
A laser diode is an LED with a built-in optical cavity (mirrored facets) that forces the emitted light to be coherent, monochromatic, and tightly collimated. They read your discs and carry the internet: a CD laser is ~780 nm infrared, a DVD laser ~650 nm red, Blu-ray ~405 nm violet (shorter λ → smaller spot → more data per disc). Paired with photodiodes and glass optical fiber (single-mode fiber has an 8–10 μm core), laser diodes send light pulses down hair-thin glass for kilometers — the electron-photon bridge stretched across continents.
| Quantity | Formula | Notes |
|---|---|---|
| LED series resistor | Rs = (Vin − Vf) / ILED | Round up to next standard value; target I ≈ 20 mA |
| Series LED string | Rs = (Vin − n·Vf) / ILED | Keep n·Vf < ~80% of Vin |
| Resistor power | P = I2·R = VR·I | Stay under the resistor's wattage rating |
| Photon energy | E = h·f = h·c / λ | h = 6.63×10−34 J·s, c = 3.0×108 m/s |
| Frequency / wavelength | λ = c / f | Shorter λ → higher energy → higher Vf |
| Photoresistor divider | Vout = Vin·R2/(R1+R2) | LDR position sets light- vs dark-activated |
| Optoisolator CTR | CTR(%) = (IC/ILED)×100 | Typical 50–100%; Darlington output >100% |
| Color | λ (nm) | Typical Vf |
|---|---|---|
| Infrared | 880–940 | ~1.2–1.4 V |
| Red | 650–660 | ~1.7–1.8 V |
| Yellow / Orange | 590–610 | ~2.0–2.1 V |
| Green | 565 | ~2.0–2.1 V |
| Blue | 470 | ~3.2–3.4 V |
| White | broadband | ~3.4–3.6 V |
You can now size any LED resistor, read a color off a forward voltage, drive a display, sense light, and isolate two circuits with a beam. Next, we widen the lens from light to every physical quantity — temperature, force, motion — in Chapter 6.