Diy Li-Fi Using Arduino
It's a very simple project which sends data from one Arduino to other using laser and a LDR.
You need very minimum parts to try it yourself and some basic programming skills, it will be useful project to understand the basic working of li-fi (sending data using light)
Components required:
- Two arduino (any type of arduino will work)
- 100 ohm resistor
- A cheap laser
- LDR
- Some wires and
- soldering supplies
Connections
Firstly remove the laser from its external shell and connect the extended wires to its terminal(don't remove laser focusing assembly), and puts male connectors to other end of wire to connect it to arduino. Laser part is done here.
Now make the receiver circuit using LDR and 100 ohm resistor acc to the circuit diagram above.
Connect the laser positive pin to arduino pin 7(or any other pin as defined in code) and the receiver side sensor pin to arduino analog pin A0.
Setting Up
It is the most important stop and hardest step atleast for me :) All you need to do in this step is to align the laser infront to the LDR.
Use rigid things for mounting the laser and receiver part, as a little movement could cause failure in transmission.
If i found better way for alignment i will update here.
Code
All the code for this project can be found at my git hub
Imp- Put bin.h file and transmitter.ino in the same folder
Upload transmitter.ino and receiver.ino to respective arduinos. To send text, enter the text in serial monitor of the transmitter and hit enter. Hopefuly you will be receiving the same text at receiver side.
I am using 128 ascii characters, so its can send almost all common keyboard symbols. You can easily extend for full 256 ascii characters.
Explaining the Code
This step is totally optional for average people, only for nerds--_--
All the code is written by me from scratch, might not be very efficient and its very basic i even don't use millis() in my whole code. Pros control your anger and don't disrespect in comment(pun intended)
Open the code in another window, you will understand the explanation better.
Transmitter part-
bins.h file contains 2d array, arranged such that the indexing of each 8 bit binary val is the decimal value of its corresponding character which makes it easy to search and send each char binary value.
txnDelay is actually the pulse width of each bit in ms, since LDR is not very responsive to the change in lighting, 50ms is actually optimal in testing where i was getting least to no errors.
Each char is send with 9 bits value where first bit the sync bit (always high), and other 8 bits are char value. Sync bit synchronize the receiver with transmitter.
The code runs once for each char and sync process is repeated before each char which make possible to send infinite characters(theoretically) without any sync issue (accomplished by start() function).
sendChar() takes each char from serial monitor and writes 0s and 1s as laser high or low state.
Receiver part-
ref variable stores LDR HIGH cutoff value. In the loop() as the LDR senses Laser HIGH (sync bit), it calls startListening() which waits for 3*txnDelay/2 which means its leaves the sync bit and another half of txnDelay to start listening at the middle of each bit (reduces the probability of encountering misinterpretation of bits).
for loop reads LDR state for each pulse and stores in a[8] array as int format and then printChar() converts into decimal value and print its corresponding char.
Pretty simple idea....