2. How much will be the error rate in both above Situations in similar conditions

3.Is a hardware Uart necessary for IR transmission?

here's what I'm assuming

1.I will connect the transmitter IR LED to a normal I/O pin and IR receiver (2-pin LED style) to an ADC

2. at the startup the program will calculate a threshold value using the ADC value from ambient light (will also re callibrate when too much error)

3. A software loop will control the whole logic! (fast speed is not a concern)

4. the loop will transmit one data bit in each iteration of the loop that will keep the LED on/off for a time long enough that the receiver on other unit has sufficient time to react to it and and the receiving MCU can take a proper ADC reading.

5.if ADC (value > threshold) then bit=1 else 0

6.then it will wait to receive the IR signal for the same time while the other replies

so as you can see I am willing to provide enough time for sampling through ADC hence I will get low speed .. and I'm fine with 100bps since my required data is just 2 byte per second..

Do yourself a huge favor and use one of those special 3 pin receivers. They have an amp and a filter inside making them very precise receivers when seeing IR light that flashes at about 40khz. They have a digital output that directly drives a digital input.

Get an IR receiver. They come at different operating frequencies. 38kHz and 40kHz are common.
You will create an IR transmitter that sends a signal at the same receiver frequency. The transmitter will be modulated by the TXD signal from a UART.

The IR receiver will produce a digital signal which you feed into the RXD input of a second UART.

I've done it before with a similar UART system to what MrChips said, with the difference that I used manually generated 40kHz pulses modulated to the TX data, so transmit was done manually in a code function, not with the UART TX.

Receiving was done very easily by connecting the output pin of the IR receiver device straight to the UART RX pin, and a pullup resistor.

Datarate was good at 1200 baud and 2400 baud but got unreliable outside those values, I think the ideal baudrate is somewhere in the middle.

It won't be too difficult to do this. Your compiler might even provide library functions/routines for software UART. Do check it out.

Click to expand...

The transmitter end of this needs some special attention and I would be gob stopped if you find an existing library that covers this.

The transmitter needs to drive the LED with 40 KHz pulses of IR energy, not just a simple on/off signal. Thus some soft UART code could be easily modified to change a PWM from 50% to 0% instead of directly controlling a pin to be on and off.

On the recieve side the fancy IR receiver converts these busts to a steady logic signal any UART can handle.