Physics Project · Arduino UNO

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.

9600 Baud Rate
8 Bits per Char
120ms Bit Delay
400 LDR Threshold

How It Works

LiFi modulates light intensity to encode binary data, received by a photosensor and decoded by the microcontroller.

01
Message Input
User types a message in the Arduino Serial Monitor at 9600 baud. Each character is processed one at a time.
02
Binary Encoding
Each character is broken into 8 bits (LSB first). The LED turns ON for bit 1 and OFF for bit 0 with a 120ms delay.
03
Light Transmission
The LED flashes rapidly — invisible to the naked eye but detectable by the LDR sensor positioned in line-of-sight.
04
Optical Reception
The LDR in a voltage divider circuit converts light intensity into a varying analog voltage read on pin A0.
05
Signal Decoding
Arduino reads the LDR value 3 times and averages it for stability, comparing against a threshold of 400 to determine 0 or 1.
06
Output
Decoded bits are reconstructed into the original character and printed back to the Serial Monitor.

Components Used

Minimal, low-cost components — all available at any electronics store.

🎛️
Arduino UNO
× 1
💡
LED
× 1 — Transmitter
🔆
LDR Sensor
× 1 — Receiver
🔌
220Ω Resistor
× 1 — For LED
🔌
10kΩ Resistor
× 1 — Pull-down
🧩
Breadboard
× 1
🔗
Jumper Wires
As needed
🖥️
USB Cable
× 1 — To PC

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 UNO GND 5V A0 Pin 13 GND 220Ω LED Transmitter GND LDR Light 5V 10kΩ GND → A0 Receiver USB → PC (9600 baud)

Arduino Sketch

C++ code that handles both transmission (LED) and reception (LDR) in the same loop.

lifi.ino
#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.

Serial Monitor — 9600 baud
LiFi System Ready
Enter message:
--- Transmission Start ---
Input: kce

Character: k
Sent: 1 | Received: 1
Sent: 1 | Received: 1
Sent: 0 | Received: 0
Sent: 1 | Received: 1
Sent: 1 | Received: 1
Sent: 0 | Received: 0
Sent: 1 | Received: 1
Sent: 0 | Received: 0

Character: c
Sent: 1 | Received: 1
Sent: 1 | Received: 1
Sent: 0 | Received: 0
Sent: 0 | Received: 0
Sent: 0 | Received: 0
Sent: 1 | Received: 1
Sent: 1 | Received: 1
Sent: 0 | Received: 0

Character: e
Sent: 1 | Received: 1
Sent: 0 | Received: 0
Sent: 1 | Received: 1
Sent: 0 | Received: 0
Sent: 0 | Received: 0
Sent: 1 | Received: 1
Sent: 1 | Received: 1
Sent: 0 | Received: 0

--- Transmission End ---
Output: kce
------------------------

Setup Instructions

Replicate this project in under 30 minutes.

1
Wire the circuit
Connect LED to pin 13 via 220Ω resistor, and LDR in a voltage divider with 10kΩ to A0.
2
Connect Arduino to PC
Use a USB cable. Your PC will detect it as a COM port.
3
Open Arduino IDE
Go to Tools → Board → Arduino UNO, then Tools → Port and select your port.
4
Upload the sketch
Paste the code from the Code section above and click Upload (→).
5
Open Serial Monitor
Click the top-right icon in Arduino IDE. Set baud rate to 9600.
6
Send a message
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.

✦ Advantages
  • High-speed, secure optical communication
  • No electromagnetic interference — safe in hospitals and aircraft
  • Energy efficient — uses existing LED lighting
  • Cannot penetrate walls — naturally secure
✦ Limitations
  • Requires line-of-sight between LED and LDR
  • Affected by ambient and external light sources
  • Limited transmission range
  • Cannot work through opaque obstacles