Go Down

Topic: IR Detect example and not getting it.. (Read 2761 times) previous topic - next topic


Hi all,

I am using, trying to use the simple IR distance tutorial. [url][/http://www.arduino.cc/playground/Main/PanasonicIrSensor]
It's not working and here's what I am not getting. I had a basic stamp board nearby, and tried the same method of bit banging, a 38kHz pulsetrain on it. That one works like a champ, I can wave my hand over the IR LED and the output changes very easily. I put it on a little breadboard and then I hook it up to the Arduino Uno I have and the output never changes, meaning the sensor never sees the IR signal. I was wondering if maybe there was something with passing the variable back from the subroutine, so I tried the attached rewrite, but nothing changes.
I have tried changing from pins 4 and 5 per the demo to other pins with no effect. I also changed the digitalread to a analogread, but the analog value hovers around 1023. I am using the recommended parallax circuit as well, with 220 Ohm resistor  for the detector and a 1K for the IR LED. I have also switched around the IR LED, in case the long leg isn't the anode.  I have taken apart the circuit a couple times too. I also have used it in the dark, thinking maybe I am having IR soak from something else. Of course the Parallax circuit hasn't had those issues and it is right next to this one. Anyone have any ideas? This should be simple but I think I have spent about 3-4 hours and it's not getting better.
Code: [Select]
[///define pins. I used pins 4 and 5
#define irLedPin 3          // IR Led on this pin
#define irSensorPin 5       // IR sensor on this pin
//int irRead(int readPin, int triggerPin); //function prototype

void setup()
  pinMode(irSensorPin, INPUT);
  pinMode(irLedPin, OUTPUT);
  delay (3000);  // time to start serial window.
  // prints title with ending line break
  Serial.println("Program Starting");
  // wait for the long string to be sent

void loop()

delay (100);
//  Serial.println(irRead(irSensorPin, irLedPin)); //display the results
//  delay(10); //wait for the string to be sent
int halfPeriod = 3; //one period at 38.5khZ is aproximately 26 microseconds
  int cycles = 70; //26 microseconds * 38 is more or less 1 millisecond
  int i;
  for (i=0; i <=cycles; i++)
    digitalWrite(irLedPin, HIGH);
    digitalWrite(irLedPin, LOW);
    delayMicroseconds(halfPeriod - 1);     // - 1 to make up for digitaWrite overhead   

  int state = digitalRead(irSensorPin);
  Serial.println(state); //display the results


* This function can be used with a panasonic pna4602m ir sensor
* it returns a zero if something is detected by the sensor, and a 1 otherwise
* The function bit bangs a 38.5khZ waveform to an IR led connected to the
* triggerPin for 1 millisecond, and then reads the IR sensor pin to see if
* the reflected IR has been detected


Why do you have "int halfPeriod = 3;"?  A half period of 38.5 kHz is about 13 microseconds, not 3.

Also, why do 70 cycles when there are 38.5 cycles per millisecond?
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp



I put it on a scope and saw the parallax one was up in the 80-90kHz range, so I changed this one to make it about 80kHz, that half period makes it close to 85kHz and the 70 cycles is to make it 1 millisecond overall duration with the faster pulse train. This is one of the desperate things I tried. Thanks for looking so close.


Ok, I am still stumped. Does anyone know if this example works? http://playground.arduino.cc/Main/PanasonicIrSensor] ?

Because I have put this on a little breadboard, hooked it up to the basic stamp and it's fine. Take that same breadboard and hook up to the Arduino and it's always a 1 for output. I read through the example and logically it is fine. I put a scope on the input to the IR LED and it's certainly a nice little pulsetrain, but that output from the photodetector never changes. It will change if I unplug it from the sensor and ground it, then it's a zero. Are there some internal pullups in the micro that I am not overcoming? Any ideas will be welcomed. Thanks.


So I also have held a remote above the receive diode. Occasionally I get a 1 to switch to a 0. I'm seeing multiple people on this forum with IR sensing questions but I'm not seeing anyone say they have something working. I just want to hook up three IR LED and three detectors to determine which way someone is waving their hand over the array. Does anyone have any ideas what I am not doing right?

Go Up