Connecting the Apple unibody remote with the Arduino.

Hi,

I already found (and used) this code here. It works pretty well but its not really reliable. I get the following output in the console as I press a few button.

9
-1
9
9
9
9
9
6
6
6
6
-1
10
10
10
10
12
-1
12
-1
-1
12
12
-1
-1
12

The -1 shows the error. So, how can I fix that? Im using a TSOP31238 directly connected to Pin 11 on my Arduino. Should I put a capacitor into the supply chain? Which size 1uF?

EDIT: Its working properly! just put a 16pf Capacitor between Vcc and Gnd

Maybe the pulse lengths are too close to the limits. Run this sketch to see what values you are getting:

int ir_pin = 11;                        //Sensor pin 1 wired through a 220 ohm resistor
int led_pin = 13;                  //"Ready to Recieve" flag, not needed but nice
//int debug = 1;                        //Serial connection must be started to debug
int start_bit = 2000;                  //Start bit 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 data[31];
  digitalWrite(led_pin, HIGH);         //Ok, i'm ready to recieve
  while(pulseIn(ir_pin, HIGH) < start_bit) { //Wait for a start bit
  }
  
  for(int i=0;i<31;i++) {
    data[i] = pulseIn(ir_pin, HIGH);      //Start measuring bits, I only want high pulses
  }

  digitalWrite(led_pin, LOW);

  for(int i=0;i<31;i++) { 
    Serial.print(data[i]);
    Serial.print(" ");
  }
  Serial.println();
}

Thanks but I just edited my first post :smiley:

I fixed it by using a 47Ohm resistor on the output and a 16pf Capacitor between Vcc and Gnd. Works great!