infrared emiter

Hello,

I want to know if someone use arduino with infrared LED to send comand for consumer device (principaly DVD player), if yes how?

thank you in advance.

jhoepffner

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176098434

Hello,

I readed that post before to post myself but I want to do the other side, not receive information from remote control inside arduino but send command to dvd player (like play, pause, next marker) from arduino (and from Isadora), any idea how to do that?

Thank you

There is an application note byt Atmel AVR415 that deals will using an AVR as an intelligent RC5 IR transmitter.

The code will not be directly useable but the application note might help.

http://www.atmel.com/dyn/products/app_notes.asp?family_id=607

Look for Application note 415

Arduino code for IR sender and receiver (based in the famous post: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176098434)

RECEIVER
-----------------

int ir_pin = 7;                         //Sensor pin 1 wired through a 220 ohm resistor
int led_pin = 13;                           //"Ready to Receive" flag, not needed but nice
int debug = 0;                           //Serial connection must be started to debug
int start_bit = 2000;                   //Start bit threshold (Microseconds)
int bin_1 = 1000;                           //Binary 1 threshold (Microseconds)
int bin_0 = 400;                             //Binary 0 threshold (Microseconds)


void setup() {
 pinMode(led_pin, OUTPUT);             //This shows when we're ready to receive
 pinMode(ir_pin, INPUT);
 digitalWrite(led_pin, LOW);       //not ready yet
 Serial.begin(9600);
}

void loop() {
 int key = getIRKey();             //Fetch the key
 if (key != -1) {
   Serial.print("Key Recieved: ");
   Serial.println(key);
 }
}


int getIRKey() {
 int data[12];
 digitalWrite(led_pin, HIGH);     //Ok, i'm ready to recieve
 while(pulseIn(ir_pin, LOW) < 2200) { //Wait for a start bit
 }
 data[0] = pulseIn(ir_pin, LOW);       //Start measuring bits, I only want low pulses
 data[1] = pulseIn(ir_pin, LOW);
 data[2] = pulseIn(ir_pin, LOW);
 data[3] = pulseIn(ir_pin, LOW);
 data[4] = pulseIn(ir_pin, LOW);
 data[5] = pulseIn(ir_pin, LOW);
 data[6] = pulseIn(ir_pin, LOW);
 data[7] = pulseIn(ir_pin, LOW);
 data[8] = pulseIn(ir_pin, LOW);
 data[9] = pulseIn(ir_pin, LOW);
 data[10] = pulseIn(ir_pin, LOW);
 data[11] = pulseIn(ir_pin, LOW);
 digitalWrite(led_pin, LOW);

 if(debug == 1) {
   Serial.println("-----");
 }
 for(int i=0;i<11;i++) {                 //Parse them
   if (debug == 1) {
         Serial.println(data[i]);
   }
   if(data[i] > bin_1) {                 //is it a 1?
       data[i] = 1;
   }  else {
       if(data[i] > bin_0) {           //is it a 0?
         data[i] = 0;
       } else {
        data[i] = 2;                     //Flag the data as invalid; I don't know what it is!
       }
   }
 }

 for(int i=0;i<11;i++) {                 //Pre-check data for errors
   if(data[i] > 1) {
       return -1;                           //Return -1 on invalid data
   }
 }

 int result = 0;
 int seed = 1;
 for(int i=11;i>=0;i--) {                //Convert bits to integer
   if(data[i] == 1) {
       result |= seed;
   }
   seed = seed * 2;
 }

 //patch for the weird data result
 //I wish I knew wtf is wrong
 for (int j = 0; j <= 11; j++) {
 int aux = result;
   aux -= pow(2, j);
   if (aux < 0) {
     result = j;
     break;
   }
 }
 if (result > 8) result = -1;
 return result;                             //Return key number
}

SENDER
--------------

int ir_pin = 6;                         //Sensor pin 1 wired through a 220 ohm resistor
int led_pin = 13;                           //"Ready to Receive" flag, not needed but nice
int debug = 1;                           //Serial connection must be started to debug
int start_bit = 2400;                   //Start bit threshold (Microseconds)
int bin_1 = 1200;                           //Binary 1 threshold (Microseconds)
int bin_0 = 600;                             //Binary 0 threshold (Microseconds)
int dataOut = 0;
int guardTime = 300;


void setup() {
 pinMode(led_pin, OUTPUT);             //This shows when we're ready to recieve
 pinMode(ir_pin, OUTPUT);
 digitalWrite(led_pin, LOW);       //not ready yet
 digitalWrite(ir_pin, LOW);        //not ready yet
 Serial.begin(9600);
}

void loop() {
 if (Serial.available()) {
   int val = Serial.read();
   switch (val) {
   case '0':
     dataOut = val - 48;
     break;
   case '1':
     dataOut = val - 48;
     break;
   case '2':
     dataOut = val - 48;
     break;
   case '3':
     dataOut = val - 48;
     break;
   case '4':
     dataOut = val - 48;
     break;
   case '5':
     dataOut = val - 48;
     break;
   case '6':
     dataOut = val - 48;
     break;
   case '7':
     dataOut = val - 48;
     break;
   case '8':
     dataOut = val - 48;
     break;
   default:
     dataOut = 255;
     break;
   }
 }
 int key = sendIRKey(dataOut);             //Fetch the key
 Serial.print("Key Sent: ");
 Serial.println(key);
}


int sendIRKey(int dataOut) {
 int data[12];
 digitalWrite(led_pin, HIGH);     //Ok, i'm ready to send
 for (int i=0; i<12; i++)
   data[i] = dataOut>i & B1;   //encode data as '1' or '0'

 // send startbit
 oscillationWrite(ir_pin, start_bit);
 // send separation bit
 digitalWrite(ir_pin, HIGH);
 delayMicroseconds(guardTime);
 // send the whole string of data
 for (int i=11; i>=0; i--) {
   //digitalWrite(ir_pin, LOW);
   //if (data[i] == 0) delayMicroseconds(bin_0);
   //else delayMicroseconds(bin_1);
   if (data[i] == 0) oscillationWrite(ir_pin, bin_0);
   else oscillationWrite(ir_pin, bin_1);
   // send separation bit
   digitalWrite(ir_pin, HIGH);
   delayMicroseconds(guardTime);
 }
 delay(20);
 return dataOut;                            //Return key number
}

// this will write an oscillation at 38KHz for a certain time in useconds
void oscillationWrite(int pin, int time) {
 for(int i = 0; i <= time/26; i++) {
   digitalWrite(pin, HIGH);
   delayMicroseconds(13);
   digitalWrite(pin, LOW);
   delayMicroseconds(13);
 }
}

We tested today and reached 5 meters without having to even switch the LED with a transistor.

/d

We tested today and reached 5 meters without having to even switch the LED with a transistor. /d

I know im bumping an old post, but why would you have to swtich the LED with a transistor?

Hi, infrared Leds are sometimes driven with very high currents (100mA) for a maximum range.

This is possible (check datasheet) because there are only very short periods of time (in RC5 code 14 pulses of 1.7ms) where this current actually flows through the Led. The max current the Arduino can source is 40mA so you have to use a transistor if you want to go beyond that limit.

Eberhard

Oh great thank you :) got it now. btw, I loaded this code on my arduino, and had a TV-B-GONE as a remote control and pressed the button in front of the IR LED receiver, but i couldnt see anything in the black arduino screen, is something wrong with my IR receiver? (the tv-b-gone works fine)

Hi,

is something wrong with my IR receiver? (the tv-b-gone works fine)

There are all sorts of infrared receivers which operate at different base frequencies. Like the TSOP1736 that expects to work at 36kHz and the TSOP1738 that, you guessed it, works at 38Khz. The receiver must match the sender to recognize commands.

Eberhard

I bought both of my leds from the same sale in ebay, so they must be at the same frequency, right? Did i place my parts right on the arduino? I just have an infra red receiver on pin 2 that goes to the ground. nothing else. Thanks.

Hi,

here is a link http://www.sbprojects.com/knowledge/ir/ir.htm to the basic idea of an infrared remote control. Its not as easy as emitter-Led is switched -> revceiver is swithced on.

You should be able to check your receiver with a flashlight or a cigarette lighter or some other light source. It should do something at least. Do you have a part-number for your receiver?

Eberhard

You should be able to check your receiver with a flashlight or a cigarette lighter or some other light source. It should do something at least

What do you mean? what should I see when I use a flashlight on the receiver?

and the model number of the leds i got is LW-IR52 and LW-IR50

Hi, I meant the part-number of the receiver. With the flashlight you can check wether anything happens on the receivers output. This works for the TSOP1736 at least. Just holding it towards a sunlit window and waving in front of it with my hand lets the output switch wildly from High to Low. I don't think there is anything wrong with the leds. You can check them with most digital cameras. On my cheap canon and another one from Olympus the IR-Signal is visible on the cameras display.

Eberhard

Im still struggling on how to make my infrared receiver work, is there anything wrong with the placing of the parts? Anyone else got an idea how to make the serial screen display a couple of 1's when its receiving signals from the infrared receiver?

Thanks :)