Li-Fi Build Your Own Safe Wireless Communication Network With Arduino





Introduction: Li-Fi Build Your Own Safe Wireless Communication Network With Arduino

Li-Fi is an emerging wireless communication technology that uses visible light to transmit data.

In this instructable we make a simple Li-Fi system that can send messages from one laptop to another.

This can be used to secretly communicate with your friends in a wifi free environment.

The instructable is made for the Tu Delft course: TfCD assignment 2

Step 1: Collect the Following Components

2 laptops or PC's

circuit components:

2 Arduino unos

2 breadboards



5 connection wires

1 10K ohm resistor

2 connection cables

optional 220-ohm resistor


Arduino software

Step 2: Build the Hardware

Use the hardware components to build the two circuits.

Circuit one:

Circuit one is made to send data. 2 cables an Arduino, a breadboard and an LED is needed. The first picture illustrates the circuit with a resistor.

1. Connect a wire to digital port 10 and to the plus side of the LED (the longest wire is the plus side of the LED).

2. Use a wire to connect the minus side of the LED to the ground port on the Arduino.

Optional step: Add a 220 Ohm resistor to prevent the LED from overheating. Connect as illustrated in the picture.

Circuit two:

Circuit two is made to receive data. 3 cables, an LDR and a 10K ohm resistor are needed to make this circuit. The second picture illustrates the circuit.

1. Use a wire to connect the 5 volts to one side of the LDR.

2. Use a wire to connect the other side of the LDR to analog port A0.

3. Connect the 10k Ohm resistor to the side of the LDR that is connected to port A0, as illustrated in the picture.

4. Connect the other side of the 10k Ohm resistor to the breadboard.

5. Connect the non-connected side of the Ohm resistor to the ground on the Arduino.

Step 3: Building the Software

Use the Arduino software to build the code.

Code one:

This code tells the Arduino to blink the led for a specific amount of time. With this code, it is possible to send two messages, because this is a simple setup you can only choose from a list of predetermined messages, but you could also make different durations correspond with the letters of the alphabet and send full messages that way, it would be wise to reduce the time to send a message in that case by editing the delay times. Since you might be in a situation with more or less light than us you might need to edit the threshold sensor value in the code. To determine what this value is, uncomment the print sensor value command and check the values of the sensor when the led is on and off and take a value in between.

Copy the following code to Laptop 1.

// code for receiving using the LDR

unsigned long StartTime = millis();

unsigned long Value; unsigned long EndTime;

int Message;

boolean StartedCounting = false; //this is used to determine if the counting has started

void setup() { Serial.begin(9600); }

void loop() {

int sensorValue = analogRead(A0); //read the sensor value

delay(1); // to stabilize

// Serial.println(sensorValue); // this can be used to determine the threshold in your lighting conditions

if (StartedCounting==false && sensorValue>850){ //if the counting has not yet started and the light is on

StartTime = millis(); // This saves the current time in milli seconds

StartedCounting= true; }

if (StartedCounting== true && sensorValue<850){ // if the counting has started and the light is off

Value = millis() - StartTime; // subtract the starting time from the current time to get message time Message= Value/1000;

StartedCounting= false;

Serial.print ("Message: ");

if (Message == 1){ // change these to your own messages. the sender should also have this list so they know what they send.

Serial.println("hi"); }

else if (Message == 2){

Serial.println("wazzup?"); }

else if (Message == 3){

Serial.println("HELP"); }

else if (Message == 4){

Serial.println("top secret"); }

else if (Message == 5){

Serial.println("Penguins"); } '

else if (Message == 6){

Serial.println("LI-FI is the future"); }

else if (Message == 7){

Serial.println("#notreallythough"); } } }

Code two:

This code tells the Arduino to count the number of seconds that the LDR is lit. It couples the number of seconds to a message and prints it in the serial monitor, so make sure it is open.

Copy the following code to Laptop 1.

// code for sending the message with the LED

int Message1 = 6; // set the number of the first message you want to convey

int Message2 = 2; // set the number of the second message you want to convey boolean Message1done = false; // this will be used to determine if the first message has been sent

int i=0;

int j=0;

void setup()

{ pinMode(10, OUTPUT); //pin connected to the led Serial.begin(9600); //sets serial port for communication }

void loop(){

if ( i < Message1) { // Sending the first message. this will loop until i has reached the value of message1

digitalWrite(10,HIGH); // turn on the LED

i++; //increase i with 1

delay (1010); // wait for a second (1010 mili seconds, a little more than a second to correct inaccuracies) }

else if (Message1done == false){ // once the led has been lit long enough it will be turned off a


delay(1000); // wait a second before sending the next message

Message1done= true; // note that message one has been sent }

if (( j < Message2) && (Message1done == true)) { // sending the second message only if message one is done

digitalWrite(10,HIGH); //this code is in priciple the same as for message 1


delay (1010); }

else if (Message1done == true) { digitalWrite(10,LOW);

exit(0); // stop the execution of the code when both messages are sent } }

Step 4: Connect Everything

In this step, everything gets connected.

The sender:

1. Connect hardware one to laptop one.

2. Upload the software to blink the LED to the Arduino.

The receiver:

1. Connect hardware two to laptop two.

2. Upload the software to blink the LED to the Arduino.

Place the LDR and the LED next to each other.

Send a message.

it works best if you reset both Arduinos before sending a new message.



    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Trash to Treasure

      Trash to Treasure

    We have a be nice policy.
    Please be positive and constructive.




    Is this for people who are afraid of getting brain damage from wifi?

    That's a neat idea, thanks for sharing :)