I. R. receiver output question

Hello Everyone,

I am using the following code to detect objects with infrared using a Fio V2. (The relevant code is the first 2 lines in the main loop.)

I am confused by the output that I am getting when an object is detected. When nothing is detected a steady stream of ones is generated, however when an object is present an alternating stream of ones & zeros is produced and not the expected stream of constant zeros.

Is this typical behavior for an I. R. receiver (TSOP34830) or does it have to do with the fact that I am reading an receiver (analogue?) with a digital pin? (I am not sure if this is allowed or correct practice.)

The data variable is defined as an 8 bit byte so I cannot see how it could be reading anything extra.

Can someone please point me in the right direction and help me out with what to research next in terms of correcting my problem?

Thanks in advance,

-Z

unsigned long uSecsOld = 0;
boolean markFlag = true;
unsigned int markTime = 1000;                      //uSecs
unsigned int spaceTime = 2000;                     //uSecs

const int SigPin = 13;                             // the pin that the LED is attached to 11 (Uno)
const int ReceiverPin = 7;                         // Could use "Byte"?

void setIrModOutput()                              // sets pin 3 going at the IR modulation rate
{
  TCCR2A = 0xF0 | _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS21);
  OCR2A = 66;                                      // defines the frequency 51 = 38.4 KHz, 54 = 36.2 KHz, 58 = 34 KHz, 62 = 32 KHz, 66 = 30KHz, 33 = 60 KHz
  OCR2B = 44;                                      // deines the duty cycle - Half the OCR2A value for 50%
}


void setup() 
{
  setIrModOutput();

  Serial.begin(9600);                              // initialize serial communication:
  
  pinMode(03, OUTPUT);                             // Just enable output on Pin 3 and disable it on Pin 11
  pinMode(ReceiverPin, INPUT);                     // I. R. Reviever pin
  pinMode(SigPin, OUTPUT);
  
  uSecsOld = micros();
}


void loop()
{
  byte data = digitalRead(ReceiverPin);
  Serial.println(data, BIN);
  
 if (data == LOW)
  {
  //Serial.println ("Object Detected");
  digitalWrite(SigPin, HIGH);
  }

 else 
  {
  //Serial.println ("Scanning");
  digitalWrite(SigPin, LOW);
  }

  if (markFlag && ((micros() - uSecsOld) > markTime) ) 
    {
    //end of MARK
    uSecsOld = micros();
    OCR2B = OCR2A; //set SPACE
    markFlag = false;
    }
    
  else if (!markFlag && ((micros() - uSecsOld) > spaceTime) ) 
    {
    //end of SPACE
    uSecsOld = micros();
    OCR2B = 44; //set MARK
    markFlag = true;
    }
}

Yes IR receivers work in reverse...= inverted logic

When a modulated pulse is received ( a Mark) the output goes low. When no modulated IR is received (a Space) the output goes HIGH.

(do a search for "sb projects ir" via your favourite search engine - explains a lot about IR remote control).

The IR receiver you are using (TSOP348*30*) ...the 30 means that it is 'tuned; for receiving signals @ 30kHz modulation. This is not a commmon frequency. Most remotes controls work at 38,36,40,56,33,30 kHz. The first 4 are the most common, 56 less common then 33 with 30 rare.

So if you are using a common TV remote, you 'may' (?) get corrupted signals with this receiver.

If you are to get one general purpose IR Receiver a 38kHz one would be a good bet (eg TSOP34438)

The output is digital.

Finally, try using one of the IRlib or IRremote libraries which remove most of the hard work for you.