LiFi
Communication
System
Transmitting data at the speed of light — using an LED, an LDR sensor, and an Arduino to build a working optical wireless communication system.
How It Works
LiFi modulates light intensity to encode binary data, received by a photosensor and decoded by the microcontroller.
Components Used
Minimal, low-cost components — all available at any electronics store.
Circuit Diagram
LED on digital pin 13 with a 220Ω resistor. LDR in a voltage divider with 10kΩ pull-down on analog pin A0.
Arduino Sketch
C++ code that handles both transmission (LED) and reception (LDR) in the same loop.
#define LED_PIN 13 #define LDR_PIN A0 int threshold = 400; // Average 3 LDR readings for stable bit detection int readStableBit() { int sum = 0; for (int i = 0; i < 3; i++) { sum += analogRead(LDR_PIN); delay(5); } int avg = sum / 3; return (avg < threshold) ? 1 : 0; } void setup() { pinMode(LED_PIN, OUTPUT); Serial.begin(9600); Serial.println("LiFi System Ready"); } void loop() { if (Serial.available()) { String input = Serial.readString(); input.trim(); String received = ""; for (int i = 0; i < input.length(); i++) { char ch = input[i]; char out = 0; // Transmit + receive each bit (LSB first) for (int b = 0; b < 8; b++) { int bit = (ch >> b) & 1; digitalWrite(LED_PIN, bit); delay(120); int r = readStableBit(); out |= (r << b); delay(200); } received += out; } Serial.print("Output: "); Serial.println(received); } }
📁 The complete sketch is also available as lifi.ino in the root directory — open it directly in Arduino IDE.
Sample Output
Serial Monitor output for input "kce" — all bits transmitted and received correctly.
Setup Instructions
Replicate this project in under 30 minutes.
Connect LED to pin 13 via 220Ω resistor, and LDR in a voltage divider with 10kΩ to A0.
Use a USB cable. Your PC will detect it as a COM port.
Go to
Tools → Board → Arduino UNO, then Tools → Port and select your port.Paste the code from the Code section above and click Upload (→).
Click the top-right icon in Arduino IDE. Set baud rate to
9600.Type any text and press Enter. Watch the LED flash and see the decoded output.
Advantages & Limitations
LiFi offers unique strengths, but comes with physical constraints.
- High-speed, secure optical communication
- No electromagnetic interference — safe in hospitals and aircraft
- Energy efficient — uses existing LED lighting
- Cannot penetrate walls — naturally secure
- Requires line-of-sight between LED and LDR
- Affected by ambient and external light sources
- Limited transmission range
- Cannot work through opaque obstacles