user46297: How do i code to transmit a sequence of bit using arduino uno?My project is about a transmitter and a receiver.Arduino as the transmitter and an application as the receiver.Light sensor will detect the bits sent.How do i send a sequence of bit for example 00101010.What kind of function should i use? i am a beginner for arduino. thank you.

user30175: Bit-wise sending of a chunk of data is really just:

go through each byte of the data 
for each byte (= 8-bits), put each bit on the LED and wait

This also has some substantial drawbacks:

no error detection or correction. If you get interference on your light sensor / camera due to the environment, you will read wrong data. For this you would need to code the data with some coding scheme or append a checksum
outputting on the built-in LED on the Arduino Uno / Nano is a bad idea sine it's directly next to the power, RX and TX LED
outputting in the visible spectrum is asking for interference. That's why we have InfraRed transmissions.
receiver and transmitter might out of sync; that means that the receiver does not sample the output of the transmitter at the correct time -- you should use a preamble, oversampling and averaging at the receiver to overcome this

That said, you might be better off using other proven methods such as IR, 2.4GHz transceivers, et cetera, from my point of view. Other microcontrollers (example) have even built-in peripherals to do IR transmission according to some protocol. 
On the Arduino Uno/Nano you could also use the IRemote library to send and receive data using a cheap IR LED and a IR receiver, many of which are included in starter kits (and are also otherwise cheap). 
The code below simply takes a stream of bytes and outputs them bit-wise on the LED. Nothing else done. Also, digitalWrite is slow and should be replaced by a faster variant.
#include <Arduino.h>

/* LED to output from */
const int LEDTrans = 13;
/* Length of a symbol */
const int timeWait = 500;

const char dataToSend[] = "Hello World";

/* Transmits data bitwise */
void transmitData(const char* data, size_t length) {
    //go through each byte of the data
    for(size_t i = 0; i < length; i++) {
        uint8_t currentByte = (uint8_t) data[i];

        //Go through each of the 8 bits in the byte
        //Goes from LSB to MSB (right-to-left)
        for(int j = 0; j < 8; j++) {
            //uses Arduino.h macro "bitRead"
            bool currentBit = bitRead(currentByte, j);

            //Set the LED on/off
            digitalWrite(LEDTrans, currentBit);
            //Wait for the symbol time
            delay(timeWait);
        }
    }
}

void setup() {
    pinMode(LEDTrans, OUTPUT);
}

void loop() {
    transmitData(dataToSend, strlen(dataToSend));
    //turn LED OFF again
    digitalWrite(LEDTrans, 0);
    delay(2000);
}


46297: <p>How do i code to transmit a sequence of bit using arduino uno?My project is about a transmitter and a receiver.Arduino as the transmitter and an application as the receiver.Light sensor will detect the bits sent.How do i send a sequence of bit for example 00101010.What kind of function should i use? i am a beginner for arduino. thank you.</p>
 30175: <p>Bit-wise sending of a chunk of data is really just:</p>

<ul>
<li>go through each byte of the data </li>
<li>for each byte (= 8-bits), put each bit on the LED and wait</li>
</ul>

<p>This also has some substantial drawbacks:</p>

<ul>
<li>no error detection or correction. If you get interference on your light sensor / camera due to the environment, you will read wrong data. For this you would need to code the data with some coding scheme or append a checksum</li>
<li>outputting on the built-in LED on the Arduino Uno / Nano is a bad idea sine it's directly next to the power, RX and TX LED</li>
<li>outputting in the visible spectrum is asking for interference. That's why we have InfraRed transmissions.</li>
<li>receiver and transmitter might out of sync; that means that the receiver does not sample the output of the transmitter at the correct time -- you should use a preamble, oversampling and averaging at the receiver to overcome this</li>
</ul>

<p>That said, you might be better off using other proven methods such as IR, 2.4GHz transceivers, et cetera, from my point of view. Other microcontrollers (<a href="http://www.st.com/resource/en/datasheet/cd00161566.pdf" rel="nofollow noreferrer">example</a>) have even built-in peripherals to do IR transmission according to some protocol. </p>

<p>On the Arduino Uno/Nano you could also use the <a href="https://github.com/z3t0/Arduino-IRremote" rel="nofollow noreferrer">IRemote</a> library to send and receive data using a cheap IR LED and a IR receiver, many of which are included in starter kits (and are also otherwise cheap). </p>

<p>The code below simply takes a stream of bytes and outputs them bit-wise on the LED. Nothing else done. Also, <code>digitalWrite</code> is slow and should be replaced by <a href="https://github.com/NicksonYap/digitalWriteFast" rel="nofollow noreferrer">a faster variant</a>.</p>

<pre><code>#include &lt;Arduino.h&gt;

/* LED to output from */
const int LEDTrans = 13;
/* Length of a symbol */
const int timeWait = 500;

const char dataToSend[] = "Hello World";

/* Transmits data bitwise */
void transmitData(const char* data, size_t length) {
    //go through each byte of the data
    for(size_t i = 0; i &lt; length; i++) {
        uint8_t currentByte = (uint8_t) data[i];

        //Go through each of the 8 bits in the byte
        //Goes from LSB to MSB (right-to-left)
        for(int j = 0; j &lt; 8; j++) {
            //uses Arduino.h macro "bitRead"
            bool currentBit = bitRead(currentByte, j);

            //Set the LED on/off
            digitalWrite(LEDTrans, currentBit);
            //Wait for the symbol time
            delay(timeWait);
        }
    }
}

void setup() {
    pinMode(LEDTrans, OUTPUT);
}

void loop() {
    transmitData(dataToSend, strlen(dataToSend));
    //turn LED OFF again
    digitalWrite(LEDTrans, 0);
    delay(2000);
}
</code></pre>
