|
Getting your Trinity Audio player ready...
|
[IMAGE: Hero image of a low-power red LED transmitter facing a shrouded photodiode receiver across a tabletop with two USB-powered microcontrollers and a laptop showing decoded text] — ALT TEXT: “Smart LiFi audio and data transmitter optical-link bench demonstration”
Introduction
A light-emitting diode can do more than illuminate a surface. Change its current quickly enough and the optical output can carry information to a photodiode. That is the useful starting point for a smart LiFi audio and data transmitter. A short-range tabletop link demonstrates modulation, receiver sensitivity and ambient-light rejection without claiming to replace Wi-Fi. This project builds a slow, visible-light digital data link and explains how an analogue audio channel differs. Its success criteria are recovered bytes, observed bit errors and a documented test range, not the vague claim that information travels “at the speed of light.”
Basic online LED-to-LDR tutorials often draw a light path but skip the detector bandwidth, gain and noise problem. Some quote high data rates without showing a receiver or a repeatable error test. Others present an audio circuit using a much brighter LED yet imply its performance applies to a low-power data prototype. The result here keeps those variants distinct: a current-limited indicator LED and photodiode receiver for simple on-off keying (OOK), with an audio front-end extension described separately. Representative examples include an Arduino LiFi data tutorial, a DigiKey Maker optical-audio experiment, and a photo-receiver tutorial. Their circuits and performance claims are not interchangeable.
Theory and Working Principle
Light is the carrier; current is the signal
In OOK, an LED is switched between an illuminated and unilluminated state. The receiver turns a change in optical power into a photodiode current, then a resistor or transimpedance amplifier converts current into voltage. A threshold decides whether each timed symbol is a one or a zero. The speed of light determines propagation delay, which is negligible at tabletop distance. Throughput instead depends on the LED driver, photodiode capacitance, receiver gain and bandwidth, signal-to-noise ratio, timing recovery and coding overhead.
For this prototype, logic one means LED on and logic zero means LED off. Each asynchronous frame has a start bit (off), eight data bits (least-significant bit first), and a stop bit (on). Ten symbol periods therefore convey eight payload bits even before any packet overhead. A 10 ms symbol period gives 100 symbols/s and at most 80 raw payload bits/s, or ten bytes/s, before idle time or resynchronisation. This is an intentional teaching speed, not a LiFi industry benchmark.
A photodiode with a load resistor is simple but reveals a trade-off. Increasing the load resistance gives more voltage per unit photocurrent but also increases the RC time constant with detector and wiring capacitance, slowing edges. Ambient sunlight adds a large DC photocurrent; a nearby lamp can add time-varying interference. A dark tube around the receiver, short leads and measured threshold help more than increasing digital speed blindly. For a more capable analogue receiver, TI’s OPT101 integrates a photodiode and transimpedance amplifier; TI lists 14 kHz bandwidth with its internal 1 MΩ feedback. That component figure is not the end-to-end bandwidth of this build.
Audio requires a different path
Analogue audio varies LED brightness continuously around a DC bias. A microphone or line-level source needs an appropriate amplifier and DC operating point; a photodiode transimpedance stage recovers a small voltage; AC coupling and an audio amplifier drive headphones or a speaker. Driving a speaker directly from a photodiode will not work. A 5 V single-supply op amp may also have restricted input or output swing; choose its operating point and check the selected datasheet. TI’s LMV358 is an example of a low-voltage dual op amp, but it is not a complete optical audio design by itself.
Digital OOK and analogue amplitude modulation both alter light intensity, but they require different bias, filtering and quality measurements. This tutorial’s exact wiring and code implement data. The audio path is a defined upgrade needing its own schematic verification and distortion measurement, rather than an untested promise that the digital circuit reproduces hi-fi sound.
[IMAGE: Optical-link block diagram showing LED current modulation, line-of-sight path, photodiode current, resistor/amplifier, analogue sampling and decoded bits] — ALT TEXT: “LiFi OOK data transmitter and photodiode receiver signal chain”
[IMAGE: Side-by-side timing diagrams of digital OOK symbols and analogue audio intensity modulation, each with labelled LED bias and detector output] — ALT TEXT: “LiFi digital on-off keying compared with analogue optical audio modulation”
Comparative Overview
| Link | Strength | Constraint | Appropriate test |
|---|---|---|---|
| Visible-light OOK | Easy to see alignment and modulation | Requires optical path and noise control | Byte error rate versus distance |
| Analogue optical audio | Direct relationship between sound waveform and light | Bias and amplifier distortion matter | Frequency response and audible noise |
| Wired UART | Reliable reference for debugging code | Requires a cable | Compare transmitter bytes and receiver log |
Do not call a single LED demo an IEEE-certified LiFi network. This is a point-to-point optical communication experiment.
Full Components List
Approximate UK prices are provisional [VERIFY: current distributor listing]. The photodiode’s actual package and spectral response must match its datasheet. Choose a low-power diffused LED and never substitute an unshielded high-power optical source without redesign.
| Component | Exact specification | Approx. UK price | Supplier | Purpose |
|---|---|---|---|---|
| Controllers | Two Arduino Uno Rev3 boards, 5 V logic | £40–£60 pair [VERIFY] | RS/Farnell | One transmitter, one receiver |
| Transmitter LED | 5 mm red indicator LED, forward voltage/current per selected datasheet | £0.20–£2 [VERIFY] | Mouser/RS | Visible optical carrier |
| LED resistor | 220 Ω, 0.25 W | Under £1 [VERIFY] | RS/Farnell | Limits LED current |
| Photodiode | Vishay BPW34 or documented equivalent, verify package and polarity | £1–£4 [VERIFY] | Mouser/Farnell | Converts received light to current |
| Load resistor | 100 kΩ, 0.25 W | Under £1 [VERIFY] | RS/Farnell | Converts photocurrent to ADC voltage |
| Optical shade | Opaque short tube or enclosure | £1–£5 [VERIFY] | Workshop materials | Rejects side illumination |
| Prototype hardware | Two breadboards, jumpers, two USB data cables | £8–£20 [VERIFY] | RS/Farnell | Isolated low-voltage assembly |
| Optional audio receiver | OPT101-compatible documented board and audio amplifier; verify supply and full circuit | £10–£30 [VERIFY] | Mouser/RS | Later analogue audio experiment |
At 5 V, a red LED with an assumed 2 V forward drop and 220 Ω resistor would draw approximately (5−2)/220 = 13.6 mA. This is an illustrative calculation; use [VERIFY: selected LED forward voltage/current and board output rating] before treating it as a guaranteed operating point. The Uno pinout identifies D9 and A0.
Circuit Design and Schematic
On the transmitter, connect D9 through 220 Ω to the LED anode and connect its cathode to ground. The controller drives only one small indicator LED. On the receiver, connect photodiode cathode to 5 V, its anode to A0, and 100 kΩ from A0 to ground. In this reverse-biased configuration, photocurrent develops a voltage across the load. Verify the BPW34 package polarity against the exact Vishay datasheet before soldering. The two Unos use separate USB supplies; they have no shared electrical signal and do not need a cross-device ground connection for the optical link.
Place the photodiode inside a short opaque tube pointed at the LED. Test at a modest tabletop separation first. The receiver samples the photodiode at A0 and applies a threshold calibrated from its measured on and off levels. The source and detector should face each other while avoiding direct sunlight and fluorescent lighting during first validation. A 100 nF local supply bypass capacitor near each controller’s add-on circuit helps reduce supply noise, although the Uno boards already have their own decoupling.
[IMAGE: Separate transmitter and receiver schematics: Uno D9 through 220 Ω to LED anode; BPW34 cathode to 5 V, anode to A0 with 100 kΩ to ground; no electrical cable between boards] — ALT TEXT: “LiFi transmitter and photodiode receiver schematic for a 5 V optical data link”
PCB Layout Considerations
Keep the photodiode-to-A0 node short and shielded from digital clock and USB cable routing. A high-value load resistor makes that node susceptible to capacitive pickup. Put the load resistor beside the photodiode connector and a ground guard or ground plane around the analogue input where appropriate. Maintain a clean return path; do not route transmitter LED pulse current through the receiver’s analogue ground, even on a combined test board.
Put visible polarity and optical-axis marks on the PCB. A mechanical shroud often improves range more than another firmware tweak. Separate transmitter and receiver boards help make the optical-only nature of the link unambiguous. Add test points for LED drive, photodiode voltage and ground, and allow a jumper to select a documented alternative load resistance during experiments. If an op amp is added for audio, its feedback loop must use the manufacturer’s recommended layout and bypass network.
[IMAGE: PCB placement illustration with LED at transmitter board edge, shrouded photodiode at receiver edge, short high-impedance analogue trace and local resistor] — ALT TEXT: “Optical transmitter and receiver PCB layout with protected photodiode input”
Step-by-Step Build Instructions
- Identify optical polarity. Check LED anode and BPW34 cathode against their actual datasheets. Do not infer package markings from a different photodiode model.
- Build the transmitter. With USB disconnected, wire D9 → 220 Ω → LED anode and LED cathode → ground. Power up and run a short LED blink test before uploading the final transmitter code.
- Build the receiver. Connect BPW34 cathode to 5 V, anode to A0, 100 kΩ from A0 to ground. Start with its shield tube fitted but not sealed, so alignment is easy.
- Characterise light levels. Run the receiver sketch in calibration mode. Record the A0 reading when the transmitter LED is held off and on at the intended distance. The threshold must fall clearly between them; if they overlap because of ambient light, move or shade the setup.
- Upload both sketches. Set transmitter and receiver Serial Monitors to 115200 baud. The data timing uses two independent controllers; no shared clock wire is required because the receiver finds the start transition in each byte.
- Align close first. Point LED into the tube at a few centimetres, observe decoded characters, then increase separation gradually. Note orientation and room lighting at every test distance.
- Run repeatable comparisons. Send the same short phrase repeatedly and count changed, missing or extra characters. Repeat with an obstructed beam and under a second ambient-light condition.
- Document receiver limits. A waveform capture across the load resistor shows whether transitions are clean or slow. Adjust threshold only after measuring on/off distributions. Do not invent a maximum range from one successful message.
[IMAGE: Breadboard prototype showing transmitter LED facing a black receiver shroud with photodiode at the rear and separate USB-powered Uno boards] — ALT TEXT: “LiFi audio and data prototype breadboards with visible LED-to-photodiode path”
Firmware and Code Walkthrough
The example sends a repeated HELLO\n message. Each byte has a dark start bit, eight data bits and a lit stop bit. Keep ambient light steady during calibration. On the receiver, measure the ADC average for LED-off and LED-on during a controlled setup, then set THRESHOLD midway. The default shown is deliberately a placeholder; [VERIFY: measured receiver ADC threshold] is essential.
Transmitter sketch:
const byte LED_PIN = 9;
const unsigned BIT_US = 10000; // 100 symbols per second
void symbol(bool on) {
digitalWrite(LED_PIN, on ? HIGH : LOW);
delayMicroseconds(BIT_US);
}
void sendByte(byte value) {
symbol(false); // start bit
for (byte bit = 0; bit < 8; bit++) {
symbol(value & 1); // least-significant bit first
value >>= 1;
}
symbol(true); // stop bit, return to lit idle
}
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH); // idle high
}
void loop() {
const char msg[] = "HELLO\n";
for (const char *p = msg; *p; ++p) sendByte((byte)*p);
delay(300);
}Receiver sketch:
const byte SENSOR_PIN = A0;
const unsigned BIT_US = 10000;
const int THRESHOLD = 400; // VERIFY: midpoint of measured LED on/off ADC
bool lightOn() { return analogRead(SENSOR_PIN) > THRESHOLD; }
void setup() { Serial.begin(115200); }
void loop() {
if (lightOn()) return; // wait for falling edge from lit idle
delayMicroseconds(BIT_US / 2);
if (lightOn()) return; // glitch rejected: start bit not still dark
byte value = 0;
for (byte bit = 0; bit < 8; ++bit) {
delayMicroseconds(BIT_US);
if (lightOn()) value |= (1 << bit);
}
delayMicroseconds(BIT_US); // sample nominal stop-bit centre
if (!lightOn()) return; // framing error: discard byte
Serial.write(value);
unsigned long start = millis();
while (!lightOn() && millis() - start < 50) {} // bounded recovery
}This is an educational, mostly blocking receiver. The transmitter inserts a start bit and the receiver checks it halfway through, samples successive bit centres and discards frames lacking a lit stop. Actual analogRead() execution adds timing overhead; at this slow symbol rate it should be measured rather than assumed negligible. The final wait has a 50 ms bound so a stuck-dark detector can return to the main loop; a field-ready version also needs explicit framing and checksums. The timing is intentionally modest to keep a resistor-loaded photodiode usable without a comparator. Do not market this as high-speed LiFi.
Testing and Calibration
With the LED continuously off and continuously on, record at least several dozen receiver ADC samples under each condition. The threshold should be between the two distributions, with room for ambient drift. If off and on readings overlap, improve alignment, shorten distance or shield background illumination. Verify the two boards are stable on USB power and the transmitter LED resistor does not heat.
Send a known repeated message. Count received bytes and corrupted bytes for a fixed time, record range and light conditions, then repeat with the receiver moved slightly off-axis. A useful metric is byte error rate: erroneous or missing bytes divided by attempted bytes. This simplistic framing lacks a sequence number, so missing bytes may be hard to count; a later protocol should include numbered packets and CRC. To test audio separately, feed a modest line-level test tone through an amplifier/bias stage designed from an actual audio schematic, then measure received waveform, gain and distortion; the two Arduino sketches do not transmit analogue audio.
[IMAGE: Oscilloscope photograph with LED-drive digital waveform above photodiode A0 voltage below, showing distinct on/off levels and a measured threshold] — ALT TEXT: “LiFi optical-link calibration waveform and photodiode threshold”
Safety Considerations
Use a low-power visible indicator LED and a current-limiting resistor. Do not stare into the LED at close range or substitute a laser or high-power LED. Keep all circuits USB/low-voltage, away from mains-adjacent lighting conductors. Avoid rapid visible flicker in a demonstration accessible to others; the bitstream can produce visible modulation. For an enclosure or public demonstration, review applicable optical safety and accessibility requirements with a qualified person. No RF licence is involved in this optical link, but that does not remove ordinary electrical or optical precautions.
Troubleshooting
| Symptom | Likely cause | Practical fix |
|---|---|---|
| No changing ADC voltage | LED/photodiode polarity wrong or bad alignment | Check device drawings and illuminate receiver deliberately |
| Always reads light on | Ambient DC saturates or threshold too low | Shade photodiode, remeasure on/off readings |
| Always reads light off | Threshold too high or optical power insufficient | Align and measure voltage before changing code |
| Correct close, errors farther away | Signal-to-noise margin falls with distance | Add shroud, reduce symbol rate or use amplifier |
| Characters shift or become garbled | Receiver misses start or sample timing drifts | Inspect waveform; lower rate, add comparator/framing |
| Works in dark, fails under room lamp | Lamp flicker or ambient light modulates detector | Shield, filter and characterise room-light spectrum |
| LED appears lit but no data | Transmitter stuck idle or code not uploaded | Probe D9 and check sketch/port |
| Audio has hum or clipping | Missing bias, front-end saturation or supply noise | Revisit analogue design and operating point |
Performance Results
The digital symbol interval is 10 ms by code, so the nominal symbol rate is 100 symbols/s. Ten symbols per UART-like frame convey eight payload bits: nominal maximum payload before gaps is 80 bit/s. Actual goodput [VERIFY: measured successfully decoded bytes/s]. Reliable range [VERIFY: LED/receiver alignment, shroud and ambient-light trial]. Byte error rate [VERIFY: counted packets in specified conditions]. Receiver rise/fall time [VERIFY: oscilloscope measurement at A0]. Audio frequency response and distortion [VERIFY: built and measured analogue variant]. The OPT101’s published component bandwidth does not establish optical-link range or audio quality on its own.
Upgrades and Variations
Add a comparator with hysteresis after the photodiode stage to turn marginal analogue transitions into cleaner digital edges. Use numbered packets, CRC and timeouts so the receiver can quantify dropped data and recover from a blocked beam. Manchester coding provides frequent transitions at the cost of additional symbol overhead. A photodiode transimpedance amplifier improves sensitivity, but gain and bandwidth must be chosen together and verified against ambient saturation.
For audio, build a separate biased analogue LED driver and photodiode amplifier, characterise its small-signal frequency response and compare speech with a wired reference. Avoid promising simultaneous high-quality audio and high-speed data from an unmeasured simple LED link. More elaborate LiFi systems use complex modulation, optical front ends and network protocols; the point of this project is a testable physical layer.
[IMAGE: Finished enclosed tabletop optical link with transmitter LED aimed at receiver aperture and displayed recovered message] — ALT TEXT: “Finished smart LiFi optical data transmitter and photodiode receiver”
FAQ
Is LiFi the same as Wi-Fi?
No. This prototype communicates over modulated visible light and needs an optical path. Wi-Fi uses radio and established networking protocols; a simple LED link is not a direct substitute.
Can an LDR receive high-speed optical data?
An LDR is useful for slow brightness changes but usually a poor choice for faster bit transitions. A photodiode and suitable analogue front end provide a better starting point; measure the actual assembled bandwidth.
What is on-off keying?
OOK assigns different LED light levels to digital symbols. In this project an illuminated LED represents one and an unlit LED represents zero, with a defined start and stop bit per byte.
Does a brighter LED always improve range?
No. Alignment, receiver saturation, background light, detector area, optics and noise also matter. Do not exceed the selected LED’s current or optical safety limits.
Can the data circuit carry audio as wired?
The supplied sketches transmit digital characters. Analogue audio needs a biased current driver and an amplified, AC-coupled receiver with measured frequency response.
Why does my receiver work only in a dark room?
Ambient light can shift or saturate the photodiode voltage and can introduce flicker. Shade the detector, record on/off distributions in the actual room and recalibrate the threshold.
Conclusion
A useful smart LiFi audio and data transmitter project starts by separating a testable digital OOK link from a proposed analogue audio extension. Build the low-power link, measure detector voltage and count decoding errors before increasing distance or speed. When the circuit moves beyond breadboards, our PCB design guide and contact page can help turn the optical front end into a robust prototype board.
