making successful IR communication

Discussion in 'Embedded Systems and Microcontrollers' started by allahjane, Jan 6, 2013.

  1. allahjane

    Thread Starter Member

    Sep 19, 2012
    75
    1
    Hello to all,


    I want to make IR digital communication between two AVR MCUs but I have no idea about the practical restrictions and hurdles.

    Here are my questions.

    1. Do i need a specialised IR receiver (three pinned packages) or simple IR receivers (those 2-pin black LED types) will do!

    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..

    so given Speed is not a concern will the above setup work?
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    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.

    They are very available too, even Radio Shack sells a good one.
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,365
    Do not use an ADC. Do what Ernie says.

    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.

    Bingo! You have created an IR serial communications link.
     
  4. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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.
     
  5. allahjane

    Thread Starter Member

    Sep 19, 2012
    75
    1
    thanks folks I get what you are saying but sorry I forgot to mention in the first post that the Hardware UART will be unavailable. I'm already connecting the UART to MAX232 !

    should i use I/O pins as soft UART?
     
    Last edited: Jan 7, 2013
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Why not? That might be easier anyway as the LED drive signal needs to be gated on and off at 40KHz, so the straight hardware UART can't do it by itself.

    Is there a PWM output available? That would be the simplest (from a software standpoint) thing to drive. But a simple digital pin could also work just fine.
     
  7. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    It won't be too difficult to do this. Your compiler might even provide library functions/routines for software UART. Do check it out.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    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.
     
    Tahmid likes this.
  9. allahjane

    Thread Starter Member

    Sep 19, 2012
    75
    1
    mistaked post
     
    Last edited: Jan 13, 2013
Loading...